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

Increasing velocity in this trajectory example?

Asked by 5 years ago

Hello! I'm not an advanced person into this kind of topic and I was wonder how to increase the velocity/speed of the part while also increasing the range available, here's the model I was looking at.

local pa, pb, project = workspace.Model.PointA,workspace.Model.PointB,workspace.Model.Projectile;
local PBPos, PAPos = pb.Position - Vector3.new(0,pb.Position.Y,0), pa.Position - Vector3.new(0,pa.Position.Y,0);
local Distance = (PBPos - PAPos).magnitude
local InitialVelocity = 200
local Gravity = 196.2
local YDifference = ((pb.Position.Y - pa.Position.Y))
local Determinant = (InitialVelocity ^ 4) - (Gravity * ((Gravity*(Distance^2)) + (2*YDifference*(InitialVelocity^2))));
local Root = math.sqrt(Determinant)
local Theta = math.atan(
    ((InitialVelocity ^ 2)
    +
    Root)
    /
    (Gravity*Distance)
)

-- Launch part
project.Anchored = true;
project.CanCollide = false;

-- Find length of opposite side of triangle (height adjustment)
local LengthOfOpposite = Distance * math.tan(Theta)
project.CFrame = CFrame.new(pa.Position, Vector3.new(pb.Position.X, pa.Position.Y, pb.Position.Z) + Vector3.new(0,LengthOfOpposite,0))
project.Anchored = false;
project.Velocity = project.CFrame.lookVector * InitialVelocity

If I'm not mistaken, increasing initialvelocity will increase the range of moving the parts from each other, but consequently, it also lowers the time to hit the partB.

Any way to make this faster? Thank you!

Answer this question