I'm pretty new to writing scripts, but I have one in mind that I think would be pretty cool. For this script, I want to keep a variable up to date on the position of an object. My current plan is to write the script in a way that expects a logic_timer to continually run the script. However, I would rather do as much of this in the actual script as possible. Is there a way to get a script to refire at a steady interval by only using the script itself?
Scripting Refire
There is, in fact. VALVe used something called a "think function" in their scripts, but the following does the same thing and is rather easier to work with.
function refire(){
EntFireByHandle(self,"RunScriptCode","refire();",0.1,null,null);
}
I have another question though. In the same script, I want to get an object to move forward. There is a SetVelocity() function. How do I deturmine whether the specified vector is local to the entity, or a global vector?
Goldenknighttim wrote:
Thanks Felix, but all I got from that was that velocity is always global. That's fine though, I've got another idea for moving an object in a locally oriented direction. It's based on the assumption that SetOrigin() can be used to move an object around. I'll test that out later this morning.
You can use SetOrigin, but it'll be jerky and can put the object inside walls. Changing velocity is better.
Goldenknighttim wrote:
I did use SetOrigin() this morning, and that's exactly what happened. But I found that I could make it smoother by setting the refire rate to a higher rate, and I plan to use the TraceLine function to tell whether it runs into a wall, and if there is ground beneath it. Unfortunately, setvelocity does not work at all. I'm using a pedistal button entity for testing. I'm guessing that setvelocity only works with a few entities.
TraceLine is glitchy and only detects world brushes (as well as one particular brush entity, but that's another bug).
SetVelocity only works on things which can move. Pedestal buttons cannot unless they are parented.
I already finished the code, but as it is, it would go through other entities, so some editing would help.
. I'm sure I can find a way to stop that from happening.
local ent = Entities.CreateByClassname("game_text");