How to find time( t = d*s ) if speed has a constant acceleration? (help)

i am making a a zipline and the slope angle of zipline determines acceleration on the zipline but i need to be able to know when in seconds how long the player will be on the zipline but i cant use

t = d*s because the player accelerates while on the zipline so how do you find how long they will be on the zipline if their speed has a constant acceleration?

https://gyazo.com/7a301a8c54dea8645c48e2544f2c914b

i cant stop the player from overshooting in the zipline because touched event is too buggy and unresponsive, i dont want to cast a bunch of rays along the way to detect the pole. how do you get time? so that i can perfectly time when to destroy the bodyvelocity and set the players velocity to 0?

1 Like

You can use a bit of easy level calculus to calculate the time

If:
acceleration = a
With the unit studs/sec^2
Taking the area under the function acceleration(t)=a (or the function of how acceleration changes over time, it doesnt change so its just a constant, a) will give you the function of velocity
The area is just base * height, where base is time and height is acceleration
This makes sense because the x axis is time, and multiplying studs/sec^2 by seconds will give you studs/sec, or velocity
So:
velocity(t) = a * t
Now you could use calculus then to find the area under the velocity curve to get the function of the distance traveled over time, but as you can see its just in the form of y=mx+b which can be represented as a triangle so we can just use the triangle area formula to calculate it
Area = 1/2 B * h
B, or base length is the input, t
h is the height at that input, or velocity(t)
So, therefore, plugging these into the formula
Area(t) = 1/2 * t * velocity(t)
Or
Area(t) = 1/2 * t * (a * t)
This can be simplified, and like earlier we have proven that the area is equal to the next highest degree of motion, so area(t) is the function of distance over time
distance(t) = 1/2 * a * t^2
Now, because we know the distance but we want to know time, we need to solve for time in this equation (like taking the inverse)
Say x is distance
x = 1/2 * a * t^2
t = sqrt(2x/a)
Or
time(x) = sqrt(2x/a)
That function can be read logically as:
The time to travel a distance, x, while accelerating at a constant rate, a, is equal to sqrt(2x/a)

I don’t think trying to time it perfectly is a good idea. That could get buggy on laggy clients.

Instead I would just check if they’ve passed the end of the zipline every frame. You don’t need to raycast or use the touched event.

If your zipline is a line from a to b, and pos is the position of the character, then you can check if they’ve gone past the end of the zipline like this:

local function IsPastEnd(pos, a, b)
	local ab = b - a
	local v = pos - a
	return v:Dot(ab.Unit) > ab.Magnitude
end

that was a good idea but for some reason after trying this it still overshoots:

i try to set the players humanoidrootpart velocity to 0 after destroying the bodyvelocity but this still happens

if IsPastEnd(char.HumanoidRootPart.Position,Attachment_A.WorldPosition,Attachment_B.WorldPosition) then
	Ziplining[char.Name] = false
	Bv:Destroy()

	char.HumanoidRootPart.Velocity = Vector3.new(0,0,0)
	print("reached end")
end

https://gyazo.com/70fece616344cd9924b066e907566430

i put a print statement to see if it runs and it does but it stll overshoots

I think that’s just an issue with how you’re stopping the character. It seems like it’s detecting correctly.

Maybe try setting the humanoid state to RunningNoPhysics or anchoring it for one frame or something.

I think there are other dev forum posts about stopping a humanoid from moving.

i figured out why. its because i made the zipline purely serversided.

why did i even try doing this on the server when i know this is normal behavior. thanks for ur idea too.

i send a msg to the client where all my parkour stuff is coded so it would make sense to include ziplining into that as well. it works perfectly together. its like a putting a triangle in a triangle hole and what i was doing was putting a square into the triangle hole.