Calculating landing position of part while in air

How would I go about getting the landing position of a travelling part? I belive it has something to do with velocity but im not sure.

And is there anyway to predict the curve that the part will be travelling in? This is probably hard math stuff but I couldn’t tell because I am not really good at math.

unless it’s going to land on a flat plane or a predictable shape such as a sphere for a planet, it isn’t really predictable.
The best you could maybe do is having a the projectile raycast forward and downards a bit, move to that position if there’s nothing or do something if there’s something

I saw this video from someone where they made something like this and I am not sure how though. Maybe he used prediction or calculating the velocity and stuff.

1 Like

each ball takes the last position and add the velocity of the car on top of that.

local LastPos = CarPos
for i = 1,Balls do
--create new ball
Ball.Position = LastPos + CarVelocity
LastPos = Ball.Position
end

I tried the script you wrote and it seems to be showing the direction the part is heading towards. Im sure its somewhat close to the final result of the calculation but still, I’m not sure how he made the car thing.

local part = workspace:WaitForChild("Part")

part.Touched:Connect(function(hit)
	if hit.Name == "Baseplate" then --part hit floor
		hitPosition = part.CFrame
	end
end)

I am trying to get the landing position while the part is till in the air, but thanks anyways! :slight_smile:

Then it hasn’t yet landed, might want to fix your title.

Yeah I guess I wasn’t clear enough, I don’t really make many posts on devforum.

So, smellfish_360 was right, but when it comes to jumping you need also to calculate gravity

Your best option is Bezier Curves

It allows you to create curves that can be manipulated easily, and there are also many resources on it if you’re confused.

I was actually thinking of using Bezier Curves but I can’t seem to figure out how to actually implement them into the code as I have tried using them before.

My best advice is to not get overwhelmed by the complex equations, as alot of it is just plugging in values into a function.

There are many resources and topics on bezier curves. This seems like a nice one Can anyone explain bezier curves in the most simple way possible please?.

Thank you I looked into the post and I made a little bezier test thingy that moves a part across it, and I got an answer from the person that made the car calculation and he sent me some formulas that has to do with it. He calculated it using a Projectile Motion problem.


But as I said earlier in the post is that I am pretty bad at math so I have no idea how I will be able to implement this.

Something like this is actually pretty simple to do. You will need to know a bit of maths though.

You can integrate to get from Velocity to Position. (Calculus)

Since you know the Velocity of a Part you can simply “keep going” and just keep stepping forward. E.g.

local futurePosition = table.create(5,Vector3.new())
local futurePredctions = 5 -- How far into the future we go
local DeltaTime = 1 -- this is the amount of time before we "plot" another point. Smaller values give you a smoother curve

-- we will predict 5 seconds into the future with each prediction being 1 second apart

local Velocity = Part.AssemblyLinearVelocity -- Get parts Velocity
for i = 1, futurePredictions do
    futurePosition[i] = Part.Position + (Velocity * i)
end

This piece of code will give us a Future prediction of where a part will be given its current Velocity.

You will notice however that the predictions are a straight line. That’s because you will need to take into account acceleration too.

It really depends on how you calculate the acceleration first. The most accurate way is to simply store the previous two Velocities and then simply get the difference. For example.


local V1 = Part.AssemblyLinearVelocity
local Accel = Vector3.new()
local V0 = V1

RunService.Heartbeat:Connect(function(deltaTime)
    V1 = Part.AssemblyLinearVelocity
    Accel = (V1 - V0)/deltaTime
    V0 = V1
end)

This piece of code gets the Acceleration of a part each frame.

Or if your projectile will not have a changing acceleration then you can simply get the worlspace.Gravity and then turn it into a downward Vector.

Then instead of having a constant Velocity update the Velocity each Prediction with the deltatime you are using.

local Velocity = Part.AssemblyLinearVelocity -- Get parts Velocity
for i = 1, futurePredictions do
    futurePosition[i] = Part.Position + (Velocity * i)
    Velocity += Acceleration * DeltaTime
end

If you don’t need precision then this solution probably isn’t for you however. Hope this helps.

9 Likes

Thanks for this detailed explanation I managed to get it working!
https://gyazo.com/c931cd480344b87e0d0b4306361ec404

1 Like

I actually thought this is an interesting idea. So I just made something similar just now.

It can also be applied to Angular Velocity in the same way.

Code
local Predictions = 50

local Position = script.Parent.Part.Position
local Orientation = script.Parent.Part.Orientation
local Velocity = Vector3.new(10,10,10)
local Angular = Vector3.new(100,100,10)
local Acceleration = Vector3.new(0,-10,0)


local DeltaTime = .1


wait(5)
for prediction = 1, Predictions do
	local Alpha = prediction / Predictions 	
	local Part = script.Parent.Part:Clone()
	Orientation+= (Angular * DeltaTime)
	Part.Orientation = Orientation
	Position += (Velocity * DeltaTime)
	Part.Position = Position
	Velocity += (Acceleration * DeltaTime)
	Part.Transparency = Alpha
	Part.Parent = workspace
	task.wait()
	
end
5 Likes