• best way to get keyboard input from the driver of an entity?
    2 replies, posted
What's the best practice? (if it matters, it's a car entity and needs to check input from the driver, for things like acceleration, braking, steering, etc.) Should I just use the ENT:Think() function to check the driver's currently held down keys? or use GM:KeyPress/Release hooks to store variables in the player depending on pressed keys? Or something else? (I noticed that the Think function can miss a key press if you tap it very fast)
It depends on what your on-key-press code is. If it only needs to be ran once, I'd use KeyPress/Release. If it needs to be continuous, use ENT:Think and player:KeyDown & co. As for your notice, please read the wiki page for ENT:Think. [url]http://wiki.garrysmod.com/page/ENTITY/Think[/url]
It's a mix of both continuous inputs and basic key toggles. So I think I'll stick to the think function and just use a boolean for the toggle keys to avoid triggering them multiple times. Thanks! I found that wiki page earlier and it made the keys much more responsive. [CODE]self:NextThink( CurTime() ) return true[/CODE] But since this alters the frequency of how often everything updates, how would I do proper "delta timing" for physics forces to make them equally strong on different tickrates? _____________________________________________ Edit: This seems to work perfectly for delta timing, but please let me know if there's a better way [CODE]function ENT:Think() --get the time since last think local delta = 0 if self.LastUpdate != nil then delta = CurTime() - self.LastUpdate end self.LastUpdate = CurTime() --print(delta) -- delta can now be used to multiply physics forces and such -- Physics test, making an object hover with a physics force and using delta to make it work on different tickrates local phys = self:GetPhysicsObject() local mass = phys:GetMass() phys:ApplyForceCenter( Vector(0,0,660*mass*delta) ) --Set next think self:NextThink( CurTime() ) return true end[/CODE]
Sorry, you need to Log In to post a reply to this thread.