I have a game where players can use magic staffs. One feature is that the staff shoots a fireball where they click. Currently, I'm using the RocketPropulsion object in my fireball by making an invisible part where they click and then setting that as the target.
My problem is that once the rocket gets there it stops, Is there any other way to propel a part towards a position and continue after that position in the same direction?
For example,
With RocketPropulsion: Player one's staff is at (0,10,0) and clicks (10,10,0), with the RocketPropulsion it travels in a horizontal line and stops at (10,10,0).
What I'm asking for: Player one's staff is at (0,10,0) and clicks (10,10,0), it travels in a horizontal line and even if it gets to the end position it keeps traveling indefinitely.
Any help would be graciously accepted!
You can use the UnitRay property of the Mouse object, in combination with a BodyVelocity, to make an object travel along a vector indefinitely.
Here is a sample script with comments
local Players = game:GetService("Players"); -- Players Service local LocalPlayer = Players.LocalPlayer; -- Get player local Mouse = LocalPlayer:GetMouse(); -- Get player's mouse local Part = workspace:WaitForChild("Part"); -- This is the reference to the fireball local Speed = 10; -- Modify to desired speed Mouse.Button1Up:Connect(function() -- Mouse event you are listening to local Velocity = Part:WaitForChild("BodyVelocity"); -- BodyVelocity inside fireball local UnitRay = Mouse.UnitRay.Direction; -- Vector3 Direction of the UnitRay Velocity.Velocity = UnitRay * Speed; -- Multiply Direction by desired speed to get final velocity end)
Also note that your fireball needs to be unanchored for this to work. Because of this you might need to add a BodyForce to counteract gravity if you do not want it to influence the fireball. You would make the BodyForce's force value to:
Vector3.new(0, Part:GetMass()*Gravity,0)
BasePart:GetMass() returns the mass of the fireball, and gravity is the gravity of the game (Default is 196.2). This effectively counteracts the force of gravity (Force = Mass * Acceleration).