- Home /
How can I cause a sphere to bounce forward infinitely with the same distance
I've been trying to create this for days. I've managed to create a sphere that bounces infinitely without gaining kinetic energy at each bounce:
public float moveSpeed;
public float jumpPower;
Rigidbody rb;
void Awake()
{
rb = GetComponent<Rigidbody> ();
}
void FixedUpdate()
{
rb.AddForce (Vector3.right * Input.GetAxis("Horizontal") * moveSpeed);
}
void OnCollisionEnter(Collision other)
{
if(other.gameObject.CompareTag("Platform"))
{
rb.velocity = Vector3.zero;
rb.AddForce (Vector3.up * jumpPower);
}
}
What I'm trying to do now is to make the ball bounce from one platform to the next infinitely. But when I try to create this effect, the distance the ball travels between 2 platforms is never constant. I want the distance traveled between each bounce to stay constant (see picture above). How can I make this work?
Do not use physics. Calculate the bounce curve yourself and move the sphere accordingly, giving the illusion of actual physics.
I'm sorry, I misunderstood. By bounce curve, are you implying that I use projectile motion?
Answer by NoseKills · Jun 19, 2017 at 05:59 PM
Answer by · Jun 19, 2017 at 06:04 PM
From what I see you are adding force to the RigidBody, if you controlled the velocity directly and keep it constant you should solve your problem.
Answer by MikesNameIsMike · Jun 23, 2017 at 10:39 AM
Instead of adding force with:
rb.AddForce (Vector3.right Input.GetAxis("Horizontal") moveSpeed);
Just manually change the balls horizontal position every frame with something like this:
rb.transform.position += Vector3.right Input.GetAxis("Horizontal") moveSpeed
Your answer
Follow this Question
Related Questions
Raycast distance affected by momentum of character 0 Answers
Find all integer grid points inside sphere 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to calculate distance between objects? 5 Answers
needed velocity to reach target in required duration 2 Answers