# How to get Sprite to move at speed determined by Curve along another curved path?

Posts: 4Member

I am trying to make a top down 2d soccer game.

I have 2 sprites on the 'pitch' and have the following code which works out a curved path (as if the ball had spin on it) for the ball to travel from Player 1 to Player 2:

I have also declared another Curve which I want to use as the speed the ball travels at:
`export(Curve) var landing_curve`

I want the ball to traverse the curve dictated by the curve above. I have done this via this code:

The snippet above works to move the ball but the speed is not correct because it is not applying that which I have dictated in as 'landing_curve'. I have tried a number of methods, including trying to use a landedness value
`export (float, 0, 1, 0.01) var landedness`
which I saw in some video, and trying to interpolate my Curve to then exchange t for in the last line but I can't get it correct.

How can I write this code so my ball travels at the speed dictated by landed_curve?

I have attached my full script if that helps and this is a video of what I have so far:
https://youtu.be/BtkG-_k-UMw

Tags :

• Posts: 907Member

Why not just use ease() function to ease normalized time used to lookup the path curve?

• Posts: 4Member
edited January 14

I didn't know I could! Haha. How would I do that? Ideally I would still like to be able to customise the speed in code to get the feel of the passes right dependant on distance, but using the ease function for now would be interesting to see.

• Posts: 907Member
edited January 15

Just use eased t instead of plain t when reading from the position curve. Ease() lets you control the shape of the easing curve to a certain degree. It's similar to what you initially wanted because your velocity curve basically remaps the time parameter.

• Posts: 4Member

Thank you very much. I found a great post showing the different curves available when using the ease function, so I've picked one of those (I think 0.6) and that has sufficed. Cheers