How to make part "lean" in direction it moves

  1. What do you want to achieve? I wanna do like quadcopter, so it leans forward when moves forward, and if it moves really fast, then it leans more

  2. What is the issue? My flying thing rotates in wrong direction

  3. What solutions have you tried so far? I tried settin offset like 90 degrees, swithing X and Z coordinates, but it wont work

Code inside flying thing model

local TS = game:GetService("TweenService")

local pl
repeat
	wait()
	if #game.Players:GetPlayers() ~= 0 then
		pl = game.Players:GetPlayers()[1]
	end
until pl

local char = pl.Character or pl.CharacterAdded:Wait()

local body = script.Parent.PrimaryPart

local prevPos = body.Position

local rotVel = Vector3.new(0,0,0)
while true do
	local delta = task.wait()
	
	local nextPos = char.PrimaryPart.Position + Vector3.new(0,3,0)
	local distV = nextPos - prevPos
	
	local angleMod = CFrame.Angles(math.rad(rotVel.X)*30,0,math.rad(rotVel.Z)*30)
	
	local CF = CFrame.new(nextPos)*angleMod*CFrame.Angles(0,0,math.rad(90))
	
	TS:Create(body,TweenInfo.new(delta,Enum.EasingStyle.Linear),{CFrame = CF}):Play()
	rotVel += distV
	rotVel *= 0.9
	
	prevPos = nextPos
end

While standing
Снимок экрана (23)
While moves
Снимок экрана (24)

Thank you for any help!

1 Like

Nvm i made it so its LookVector is set to previous position with small delay

local TS = game:GetService("TweenService")

local pl
repeat
	wait()
	if #game.Players:GetPlayers() ~= 0 then
		pl = game.Players:GetPlayers()[1]
	end
until pl

local char = pl.Character or pl.CharacterAdded:Wait()

local body = script.Parent.PrimaryPart

local prevPos = body.Position

local lookPos = prevPos-Vector3.new(0,5,0)

local rotVel = Vector3.new(0,0,0)
body.CFrame = CFrame.new(char.PrimaryPart.Position + Vector3.new(0,3,0))

while true do
	local delta = task.wait()
	
	local nextPos = char.PrimaryPart.Position + Vector3.new(0,3,0)
	local distV = nextPos - prevPos
	
	
	local nowPos = body.Position
	local dir = (nextPos-(lookPos-Vector3.new(0,5,0)))
	local CF = nil
	
	nowPos += dir*1.6
	CF = CFrame.new(nowPos,lookPos)
	
	if CF then
		TS:Create(body,TweenInfo.new(delta,Enum.EasingStyle.Linear),{CFrame = CF}):Play()
	end
	rotVel += distV
	
	rotVel *= 0.9
	
	prevPos = body.Position
	
	-- slowly moving lookPos to the nextPos2
	local nextPos2 = nextPos-Vector3.new(0,5,0)
	local dist = (lookPos-nextPos2).Magnitude
	
	local dir = (nextPos2-lookPos).Unit
	lookPos += dir*dist*0.2
end
1 Like