# Getting instances of a Vector from different times?

I’m trying to get two instances of the player’s Aim Vector so that I can subtract one from the other and get the difference.

Once I do that, I want to check if the difference is greater than the average of the two vectors and if so, give the player a speed boost. I average the two vectors by adding them together then dividing the result by two.

At the moment, just calling ply:GetAimVector() returns the same vector no matter when I call it in the script. Here’s what I have so far (taken out of the init.lua of my gamemode script):

[lua]
local playermouseaim1 = Vector(ply:GetAimVector())
timer.Create(“leftkeydown”, 0.2, 0, function()
local playermouseaim2 = Vector(ply:GetAimVector())
if playermouseaim1:Length()-playermouseaim2:Length() > (playermouseaim1:Length()+playermouseaim2:Length())/2 then
ply:SetVelocity( (ply:GetAimVector()*5000)-Vector(0, 0, (ply:GetAimVector()*5000).z))
end
end)[/lua]

For convenience I only showed the relevant code.

why are you trying to pass a vector in to a vector?

Not sure which instance of “vector passing” you’re refering to. In the if statement I’m trying to check if the difference between two vectors is greater than the average of those two vectors.

The two vectors in question are the problem though because I want to get one instance of the player’s Aim Vector BEFORE the timer and one instance AFTER.
I.E: playermouseaim1 is the first instance, playermouseaim2 is the second. I want to work out the average and difference between the two.

If you mean the Vector(ply:GetAimVector()), I don’t know, it doesn’t seem to work otherwise (as in, when I set the vector it needs to be greater than to another vector other than the average of the two).

just do

``````
local playermouseaim1 = ply:GetAimVector()
timer.Create("leftkeydown", 0.2, 0, function()
local playermouseaim2 = ply:GetAimVector()

``````

done

Yes, but how do I get two instances of the same player’s aim vector at two different times? That’s what I’m trying to work out here, If I’m not being clear.

I change the playermouseaim1 and 2 variables and it breaks it completely. Here’s the whole section of the script:

[lua]function ForwardKey(ply, key)
local standingon = ply:GetGroundEntity()
if standingon:IsWorld() or standingon:IsValid() then
if key == IN_MOVELEFT then
ply:SetVelocity( (ply:EyeAngles():Right()-800)-Vector(0, 0, (ply:EyeAngles():Right()-800).z))
playerLeftAcel = 1
local playermouseaim1 = ply:GetAimVector()
timer.Create(“leftkeydown”, 0.2, 0, function()
if playerLeftAcel == 1 then
if ply:KeyDown(IN_MOVELEFT) != true then
playerLeftAcel = 0
end
if ply:KeyDown(IN_MOVERIGHT) == true then
if standingon:IsWorld() or standingon:IsValid() then
local playermouseaim2 = ply:GetAimVector()
playerLeftAcel = 0
playerRightAcel = 0
playerForwardAcel = 1
print(playermouseaim1:Length()-playermouseaim2:Length())
if playermouseaim1:Length()-playermouseaim2:Length() >= Vector(0, 0, 0):Length() then
ply:SetVelocity( (ply:GetAimVector()*5000)-Vector(0, 0, (ply:GetAimVector()*5000).z))
end
end
end
end
end )
end
if key == IN_MOVERIGHT then
ply:SetVelocity( (ply:EyeAngles():Right()*800)-Vector(0, 0, (ply:EyeAngles():Right()*800).z))
playerRightAcel = 1
local playermouseaim1 = ply:GetAimVector()
timer.Create(“rightkeydown”, 0.2, 0, function()
if playerRightAcel == 1 then
if ply:KeyDown(IN_MOVERIGHT) != true then
playerRightAcel = 0
end
if ply:KeyDown(IN_MOVELEFT) == true then
if standingon:IsWorld() or standingon:IsValid() then
local playermouseaim2 = ply:GetAimVector()
playerLeftAcel = 0
playerRightAcel = 0
playerForwardAcel = 1
print(playermouseaim1:Length()-playermouseaim2:Length())
if playermouseaim1:Length()-playermouseaim2:Length() >= Vector(0, 0, 0):Length then
ply:SetVelocity( (ply:GetAimVector()*5000)-Vector(0, 0, (ply:GetAimVector()*5000).z))
end
end
end
end
end )
end
end
end

and here’s the whole thing:
init.lua:

include( “shared.lua” )

if CLIENT then
ply = player()
local playerForwardAceleration = Vector(ply:GetAimVector()800)
local playerBackAceleration = Vector(ply:GetAimVector()
-800)
local playerLeftAceleration = Vector(ply:EyeAngles():Right()*-800)
local playerRightAceleration = Vector(ply:EyeAngles():Right()*800)

local playerAceleration = Vector(playerForwardAceleration.get+playerBackAceleration.get+playerLeftAceleration.get+playerRightAceleration.get)/4
local playerVelocity = playerAceleration
end

function ForwardKey(ply, key)
local standingon = ply:GetGroundEntity()
if standingon:IsWorld() or standingon:IsValid() then
if key == IN_FORWARD then
ply:SetVelocity( (ply:GetAimVector()800)-Vector(0, 0, (ply:GetAimVector()800).z))
playerForwardAcel = 1
timer.Create(“forwardkeydown”, 0.2, 0, function()
if playerForwardAcel == 1 then
if ply:KeyDown(IN_FORWARD) != true then
playerForwardAcel = 0
end
end
end )
end
if key == IN_MOVELEFT then
ply:SetVelocity( (ply:EyeAngles():Right()
-800)-Vector(0, 0, (ply:EyeAngles():Right()
-800).z))
playerLeftAcel = 1
local playermouseaim1 = ply:GetAimVector()
timer.Create(“leftkeydown”, 0.2, 0, function()
if playerLeftAcel == 1 then
if ply:KeyDown(IN_MOVELEFT) != true then
playerLeftAcel = 0
end
if ply:KeyDown(IN_MOVERIGHT) == true then
if standingon:IsWorld() or standingon:IsValid() then
local playermouseaim2 = ply:GetAimVector()
playerLeftAcel = 0
playerRightAcel = 0
playerForwardAcel = 1
print(playermouseaim1:Length()-playermouseaim2:Length())
if playermouseaim1:Length()-playermouseaim2:Length() >= Vector(0, 0, 0):Length() then
ply:SetVelocity( (ply:GetAimVector()*5000)-Vector(0, 0, (ply:GetAimVector()*5000).z))
end
end
end
end
end )
end
if key == IN_MOVERIGHT then
ply:SetVelocity( (ply:EyeAngles():Right()*800)-Vector(0, 0, (ply:EyeAngles():Right()*800).z))
playerRightAcel = 1
local playermouseaim1 = ply:GetAimVector()
timer.Create(“rightkeydown”, 0.2, 0, function()
if playerRightAcel == 1 then
if ply:KeyDown(IN_MOVERIGHT) != true then
playerRightAcel = 0
end
if ply:KeyDown(IN_MOVELEFT) == true then
if standingon:IsWorld() or standingon:IsValid() then
local playermouseaim2 = ply:GetAimVector()
playerLeftAcel = 0
playerRightAcel = 0
playerForwardAcel = 1
print(playermouseaim1:Length()-playermouseaim2:Length())
if playermouseaim1:Length()-playermouseaim2:Length() >= Vector(0, 0, 0):Length then
ply:SetVelocity( (ply:GetAimVector()5000)-Vector(0, 0, (ply:GetAimVector()5000).z))
end
end
end
end
end )
end
if key == IN_BACK then
ply:SetVelocity( (ply:GetAimVector()
-800)-Vector(0, 0, (ply:GetAimVector()
-800).z))
playerBackAcel = 1
timer.Create(“backkeydown”, 0.2, 0, function()
if playerBackAcel == 1 then
if ply:KeyDown(IN_BACK) != true then
playerBackAcel = 0
end
end
end )
end
end
end

function Skate(ply, move)
local standingon = ply:GetGroundEntity()
if standingon:IsWorld() or standingon:IsValid() then
if playerForwardAcel == 1 then
ply:SetVelocity(ply:GetAimVector()100)
end
if playerBackAcel == 1 then
ply:SetVelocity( ply:GetAimVector()
-100)
end
if playerLeftAcel == 1 then
ply:SetVelocity( ply:EyeAngles():Right()*-100)
end
if playerRightAcel == 1 then
ply:SetVelocity( ply:EyeAngles():Right()100)
end
else
if playerForwardAcel == 1 then
ply:SetVelocity(ply:GetAimVector()20)
end
if playerBackAcel == 1 then
ply:SetVelocity( ply:GetAimVector()
-20)
end
if playerLeftAcel == 1 then
ply:SetVelocity( ply:EyeAngles():Right()
-20)
end
if playerRightAcel == 1 then
ply:SetVelocity( ply:EyeAngles():Right()*20)
end
end
end

Just calling ply:GetAimVector() twice (at two different points in the script) doesn’t seem to give me two separate results.

bumping this. Even if I’m wrong I’d like someone to tell me so.

So, how would I be able to get two instances of the player’s aim vector?

I’ve already answered the question about getting two instances of the player’s aim vector, but that’s evidently not what you want to know.
I can’t make sense of your code. What does it do?

local playerForwardAceleration = Vector(ply:GetAimVector()*800)

You are saying Vector(Vector() * 800)
It ain’t gonna work.