• Any way to get player movement?
    6 replies, posted
In my Lua script, I need to make it so it changes your material whenever you move. However, my current method, changes the material when you press any movement-related buttons and is not very good. [CODE] if key == IN_FORWARD or key == IN_BACK or key == IN_MOVELEFT or key == IN_MOVERIGHT or key == IN_JUMP then self:SetMaterial( "models/effects/comball_tape" ) else self:SetMaterial( "sprites/heatwave" ) end[/CODE] Is there anyway I can do "if ply:IsMoving() then" or anything like that? I've checked the wikis and could not find anything. Thanks.
You could get the velocity of the player. [b][url=http://wiki.garrysmod.com/page/Entity/GetVelocity]Entity.GetVelocity [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] And then get the length of that vector. [b][url=http://wiki.garrysmod.com/page/Vector/Length]Vector.Length [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] And then do checks with that number.
[code]if ( player:GetVelocity():Length() > 0 ) then /*moving*/ else /* not moving */ end [/code]
[QUOTE=Robotboy655;40816980][code]if ( player:GetVelocity():Length() > 0 ) then /*moving*/ else /* not moving */ end [/code][/QUOTE] Do "player:GetVelocity():Length() > 5" since source can act up a bit.
[CODE] if ( self:GetVelocity():Length() > 5 ) then self:SetMaterial( "models/effects/comball_tape" ) else self:SetMaterial( "sprites/heatwave" ) end[/CODE] This doesn't seem to work. If I stand still and then hold one of W, S, A, or D, I've still got heatwave material. If I hold more than one button, then it sets the more visible material.
Might I ask where are you calling this? In a Think hook?
[QUOTE=Robotboy655;40825811]Might I ask where are you calling this? In a Think hook?[/QUOTE] I was accidentally calling it in an onkeypress. Put it in a think hook and it worked fine. Thanks.
Sorry, you need to Log In to post a reply to this thread.