Hello,
I'm trying to make something where it will force the specified player to walk/run to a specified vector. How would I achieve this? (also, i don't care about the view moving with it, the mouse is always enabled in this gamemode and players cannot use W, A, S, and D.
[url]http://wiki.garrysmod.com/page/GM/CreateMove[/url]
Either set the view angles towards the vector and just SetForwardMove or normalize a directional vector for use with SetForwardMove, SetSideMove, and SetUpMove.
For instance:
[lua]
local function myMoveToVector(cmd)
local targetang = (MY_TARGET_VECTOR - LocalPlayer():GetShootPos()):Angle() -- Add Vector(0, 0, 64) to MY_TARGET_VECTOR if you don't want the players to look down.
cmd:SetViewAngles(targetang)
cmd:SetForwardMove(MY_MOVE_SPEED) --I can't remember if this is a percentage of the walk speed or just a speed, but it will be capped anyways so just set it to the walkspeed.
--If you don't mind the player slowing down as they approach, set it to MY_TARGET_VECTOR:Distance(LocalPlayer():GetPos())
cmd:SetSideMove(0) --Making sure the player can't move sideways
cmd:SetUpMove(0)
end
hook.Add("CreateMove", "MyMoveToVector", myMoveToVector)
[/lua]
Untested code, so be wary of errors.
Okay, I got that to work. I have another problem however.
I have some code:
[code]
if (input.IsMouseDown(MOUSE_RIGHT)) then
clickPosX = gui.MouseX();
clickPosY = gui.MouseY();
end
[/code]
This is the position of the mouse at the last frame when right mouse button was held. What I want to do with these is get a global vector. There IS a [URL="http://wiki.garrysmod.com/page/gui/ScreenToVector"]function[/URL] for this, however, it converts it to a normalized vector. How would I go from normalized to world vector?
Do a traceline from the player's view pos in the direction of the normal vector I should think...
Sorry, you need to Log In to post a reply to this thread.