Hi there, I need help with making my wing script gain velocity while going downwards and lose velocity while going upwards and if the velocity is too low then it cancels
This is my code I need help with
game:GetService("RunService").RenderStepped:Connect(function()
if Flying and Float then
FlyAnim:Play()
local MousePos = Mouse.Hit.p
local lookVector = Vector3.new(MousePos.X,MousePos.Y,MousePos.Z)
character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.CFrame.p,lookVector)
FloatVelocity.Velocity = Mouse.Hit.lookVector*100
GainedVelocity = FloatVelocity.Velocity.Y
if GainedVelocity <= 15 then
Flying = false
Float = false
script.Wind:Stop()
local ActiveTracks = humanoid:GetPlayingAnimationTracks()
for _,v in pairs(ActiveTracks) do
v:Stop()
end
character.HumanoidRootPart:FindFirstChild("FloatVelocity"):Destroy()
end
wait()
end
end)
end
So I think based on your code you have the wing attached to the humanoidrootpart in some way?
If you grab the humanoidrootpart.Position it will return a Vector3, with any Vector3 you can reference a specific axis (x, y, z) like so.
HumanoidRootPart.Position.Y -- This is not a vector3 anymore, it's just a float / number
So if you have this defined outside of the scope of the runservice loop you can compare the last y position every step like so
local lastY = 0
RunService.RenderStepped:Connect(function()
local currentY = humanoidRootPart.Position.Y
if currentY > lastY then
-- they are higher than their last position
elseif currentY < lastY then
-- they are lower than their last position
end
lastY = currentY
end)
This dosen’t seem like the thing I’m trying to do, I’m trying to make the player gain velocity while going downwards and lose velocity when going upwards with the wings, And also it’s a bodyvelocity
The Velocity property of the BodyVelocity is a Vector3 I’m pretty sure, so you can directly update the value of it like you would set the position of a part.
BodyVelocity = Your BodyVelocity instance
HumanoidRootPart = the primary part of the character model
LastYPosition = The Y position of the HumanoidRootPart in the previous frame.
delta = the only parameter of RunService.RenderStepped(Float: delta)