Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I calculate the Velocity on a BodyVelocity for a fly tool? (And other problems.)

Asked by 7 years ago
Edited 7 years ago

Feeling ambitious, I decided to try to make a flying tool. The idea was that once the tool was equipped, a flying animation (Yet to be created) would play, and the player's character would fly towards the mouse, slowly gaining momentum/speed. It would slow down when going straight up, and speed up when going straight down. I set out to code it, and realized...

A) I have no idea how to tell the BodyVelocity instance what its BodyVelocity should be.

B) I am not sure how to calculate whether the mouse is going up or down. I think something like "if mouse.Hit.p.y >= character.HumanoidRootPart.Position.y" would work, but I figured I should include this part in case you guys could help me.

C) I have no idea how to keep the BodyVelocity's velocity constantly updating to follow the mouse.

D) I am not sure how to make it speed up over time. I think increasing the value of the speed variable, and then applying that to the velocity in some way might work, but I do not know how to apply it.

Here is the code. I am using a localscript to fire a RemoteEvent when the fly tool is equipped, to give this serverside script a way to get the mouse from the player.

local tool = script.Parent
local Event = script.Parent.Event
local speed = 2
local maxspeed = 100
local inertia = speed/maxspeed


Event.OnServerEvent:connect(function(player)
    print(player.Name, "has equipped the flight tool!")

    local char = player.Character or player.CharacterAdded:wait()
    local mouse = player:GetMouse()
    local HumRoot = char.HumanoidRootPart
    local BodyVelocity = Instance.new("BodyVelocity")

    BodyVelocity.Name = "Flight"
    BodyVelocity.Velocity = --This is where I tried a few things that all failed. 


end)

Answer this question