Im busy trying to get my ball to land in the exact position it should after every bounce which is the centre of the next cylinder every time it bounces from one to the other. The problem here is if i have a platform that is higher than the others then the distance travelled is longer which then means i no longer land in the exact centre of my next platform which then puts the whole flow off!
At the minute i am using rigidbody add force in fixed update. The idea is that the ball will always move to the right and bounce on every impact it has. The problem i am having at the minute is the trajectory - I want the ball to always land at the exact centre of the next cylinder no matter it’s climb or drop height!
If you need the ball to land dead center on the cylinders, my guess is you could “cheat” in your simulation by having a force on the cylinder draw the ball toward the center.
Thats a good idea! I had something where it rounded the position of the X axis which worked perfectly but when it was more than 0.2 from the centre it would snap and not look nice at all.
Hey Simo, This is defo heading in the direction i want it too. Problem at the minute is it is just going back and forth. I thought i would share the code i have too see how you would use your Velocity helper. There are redundant variables. Am i also right in thinking with your approach i can control the speed in which the ball is travelling?
public Transform nextTarget;
public UnityEvent OnPopped;
public float bounceSpeed;
public float moveSpeed;
public bool grounded;
public float radius;
public Rigidbody rb;
public Vector3 movementForce;
public void Start()
{
rb = GetComponent<Rigidbody>();
rb.isKinematic = true;
}
public void StartGame()
{
rb.isKinematic = false;
}
public void FixedUpdate()
{
rb.velocity += Velocity(movementForce, 0.5f);
}
Vector3 Velocity(Vector3 to, float reachTime)
{
Vector3 direction = to - transform.position;
direction -= Vector3.up * direction.y;
return direction / reachTime + Vector3.up * (bounceSpeed * Physics.gravity.magnitude * reachTime);
}
public void OnCollisionEnter(Collision col)
{
grounded = true;
}
public void OnCollisionExit(Collision col)
{
grounded = false;
}
public void OnTriggerEnter(Collider col)
{
if (col.tag == "Death")
{
OnPopped.Invoke();
rb.isKinematic = true;
}
}
Ahh, I did have it like that to start with, But then came the issue of knowing what the next object is, but then if i have multiple stories, i then need multiple lists or arrays to know what is next.
I managed to check it out and it works exactly like i wanted! Thank you! When i modify the reach time the bounce is smaller which then sometimes messes it up.
Is there any way i can control the speed in which it goes through its targets while keeping the bounce high? Main reason for this is so i can change this to increase / decrease the difficulty.
Ahhh, So is there a way to have constant bounce height then? As smaller reach time of course gives smaller bounce? Sorry for all the questions man haha. Really im trying to aim for just faster moving but same kind of bounce. Also with a smaller reach time sometimes it can overshoot?
I see you’ve already found a solution that works for you, but I’d also like to throw out there that DOTween, a tweening library which is free on the asset store, has a tween called DOJump, which you can specify a target location, jump power for consistent heights, movement speed or duration of the jump, how many jumps to reach the target, and it works for Transform or Rigidbody. It’s an extremely versatile and powerful library.
Besides, it’s entirely possible the tween won’t look exactly the way you want it to, so it’s still good to know how to build it yourself for more control.