Hey there!
I was wondering how I could add a lookvector to a vector3:
Anyone got ideas? I’m bad at math.
Hey there!
I was wondering how I could add a lookvector to a vector3:
Use CFrame.new(vector3).lookVector
Well I just went with this instead:
local cap = 0.5
local drag = 0.005
local devider = 100
local velocity = Vector3.zero
wait(5) local i = 0
while true do
i=i+1
wait()
local lookvector = script.Parent.CFrame.LookVector
local final = lookvector
--velocity cap
if math.abs(velocity.x)>cap and math.abs(velocity.x+(final/devider).X)> math.abs(velocity.x) then
--print('CAP FOR X: '..velocity.x)
else
velocity=velocity+Vector3.new( (final/devider).X,0,0)
end
if math.abs(velocity.z)>cap and math.abs(velocity.z+(final/devider).z)> math.abs(velocity.z) then
--print('CAP FOR Z: '..velocity.z)
else
velocity=velocity+Vector3.new(0,0,(final/devider).Z)
end
-- set to 0 on each sides to straigthen
--x
if velocity.X>0 then
velocity=velocity-Vector3.new(drag,0,0)
end
if velocity.X<0 then
velocity=velocity+Vector3.new(drag,0,0)
end
--xz
if velocity.Z>0 then
velocity=velocity-Vector3.new(0,0,drag)
end
if velocity.Z<0 then
velocity=velocity+Vector3.new(0,0,drag)
end
-- add velocity
script.Parent.Position=script.Parent.Position+velocity
--- debug
if i%2 ==0 then
local c= script.Parent:clone()
c.Parent=workspace
c.Transparency=0.5
c.BrickColor=BrickColor.new('Really red')
game.Debris:AddItem(c,2)
end
end