[ad_1]
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
Asked
Viewed
2 times
-
I’m using Unity’s latest Splines package(v2.5) to move a projectile across a spline with speed. It works perfectly and the projectile moves across the spline to it’s target with linear speed.
-
But I’d like to make it look even better by making it behave a bit more realistically. Maybe someone smarter than me can articulate how projectiles move better, but essentially, I think when a projectile is thrown it should have a burst of speed at the start and begin to rise slower as it reaches its peak height. Then as it starts to fall it should gradually begin to fall faster.
-
I’d like to use math to accomplish this, rather than something like an animation curve. The reason is because sometimes enemies will be in different positions. So, the spline will look different depending on the enemy’s position.
Here’s the code I’m using:
public SplineContainer spline;
public float speed;
public float distancePercentage;
public float splineLength;
private IEnumerator MoveTheProjectile()
{
// Move the projectile across the spline
while (distancePercentage < 1f)
{
distancePercentage += speed * Time.deltaTime / splineLength;
currentPosition = spline.EvaluatePosition(distancePercentage);
projectile.transform.position = currentPosition;
yield return null;
}
}
Since I’m already using a speed variable to move the projectile, I think implementing this should be possible.
Is anyone able to please assist me with a method of changing the speed of the projectile to be more realistic? Thanks so much!😊
\$\endgroup\$
You must log in to answer this question.
lang-cs
[ad_2]