Projectile Velocity & RotVelocity Math

I’m making a projectile script that launches a Knife for example

and I want it to spin like this

  • So no matter where it’s thrown at it will always have a straight spin

  • It will also not be effected by Gravity, so it won’t descend on the Y Axis

I want to achieve this by using Velocity and RotVelocity

No BodyMovers and Constraints

1 Like

Impossible to have the part not be impacted by gravity, you’ll need to either have something counter it (like a bodymover) or anchor it and simulate manually (not use velocity).

If you need more help it’s best to post code.

2 Likes

You have your origin point O from where you launch your knife and your target point P-
Knife is some sort of part on the knife that is supposed to be affected by the velocity/rotVelocity.
Also this assumes the knife is straight at the start of the flight

Up=Vector3.new(0,1,0)
FlyDirection=(P-O).unit
Knife.Velocity=FlyDirection * KnifeSpeed --direction times magnitude
RotationDirection=(FlyDirection:Cross(Up)).unit --Perpendicular to FlightDirection and y-Axis
Knife.RotVelocity=RotationDirection * KnifeRotSpeed --direction times magnitude

KnifeRotSpeed is a speed of your choosing as is KnifeSpeed.

5 Likes

Pretty sure a BodyForce/VectorForce would do the trick (make sure VectorForce is relative to the world). Set it’s force to workspace.Gravity * part:GetMass(). If you have multiple parts, you’ll need to calculate all of their masses and add them together. I haven’t done this recently so I could be wrong about some of the details.

Doing it manually wouldn’t be too difficult, either, (okay the core idea is easy but figuring out the specifics is a bit tough) although it may not be as reliable in terms of hit detection. Essentially for manual movement you want to calculate a few things:

  • Before you begin moving it, calculate the time (TravelTime) it’ll take to get from A to B using the length of the vector. Magnitude / STUDS_PER_SECOND if I’m thinking correctly. This will also be useful with rotation as if you have a FULL_ROTATIONS_PER_SECOND value then you can calculate how many rotations will be done when it is traveling.
  • Move it every frame using a RunService signal (Stepped would be the right one, I think?). You could do this using PositionA:lerp(PositionB, (tick() - StartTime)/TravelTime) so everything will run at a constant speed. Handle rotation in a similar manner.
  • Raycast every frame to check whether the knife has hit something (because something may come into its path that wasn’t in it before)
1 Like

Works perfectly Thank you @EmeraldSlash @sonihi @Darkmist101

-- Position
Part.CFrame = Cha.RightHand.CFrame
-- Orientation
Part.Orientation = Vector3.new(0,0,0)
-- Velocity
Part:WaitForChild('BodyVelocity').Velocity = (H.p - Head.Position).Unit * 85
-- RotVelocity
Part.RotVelocity = (H.p - Head.Position).Unit:Cross(Vector3.new(0,-1,0)).Unit * 10

I have decided to use BodyVelocity because it’s easier.

2 Likes