• Trying to modify a Vector direction
    1 replies, posted
I'm trying to make it so that when you press the w key it propels you forward in the direction you are facing and when you press the a,s and d keys you are also propelled in another direction appropriate to where you're facing (so that if you for example press a, you will be strafed to the left). I thought it would be possible to just subtract a vector from ply:GetAimVector(), but after numerous tests it has proved impossible. I have tried both simply subtracting a number as well as subtracting a number already taken from the AimVector (like in the linked example). Neither of these things have worked and have always propelled the player in a certain direction and not one relative to the way the player faces. Here's my example so far: init.lua: [lua]function ForwardKey(ply, key) if key == IN_FORWARD then ply:SetVelocity( ply:GetAimVector()*500 ) print(ply:GetAimVector()*500) end if key == IN_MOVELEFT then playerleftmod = ply:GetAimVector()-(ply:GetAimVector()-Vector(0, 1 , 0)) ply:SetVelocity( (ply:GetAimVector()+playerleftmod)*500 ) print(ply:GetAimVector()-Vector(90, 0, 0)) end end hook.Add("KeyPress", "Forward Key Pressed", ForwardKey)[/lua]
ply:GetAimVector() is the same as ply:EyeAngles():Forward(). ply:EyeAngles():Right() will give you the right vector, multiply by a negative number will give you left.
Sorry, you need to Log In to post a reply to this thread.