Hello,
I was wondering how to limit speed on one axis for an object. I have a script that limits speed for my game object but when the object falls it is also limited.
How can I limit the speed of just one axis?
Thanks
Hello,
I was wondering how to limit speed on one axis for an object. I have a script that limits speed for my game object but when the object falls it is also limited.
How can I limit the speed of just one axis?
Thanks
Well you could try reducing the amount your velocity is being affected. I think i would try
if(Mathf.Abs(rigidbody.velocity.y) > maxspeed) (rigidbody.velocity.y = rigidbody.velocity.y - 3)
if(Mathf.Abs(rigidbody.velocity.y) < -maxspeed) (rigidbody.velocity.y = rigidbody.velocity.y + 3)
Find the magic number that arrests acceleration and your good to go.
Have you tried to exchange "-3" and "+3" in @chemicalvamp's script? This is just a suggestion, but maybe you are using an "inverse" coordinate system that doesn't match exactly with that script.
– BiG[UPDATE]: or maybe "maxspeed" with "-maxspeed": now that I think better about it, it would have much sense. Not sure about that yet, however, it's just a try...
– BiGChecked and double checked this is working for me, and I took out what was unnecessary
using UnityEngine;
public class SlowFall : MonoBehaviour
{
public float maxspeed = 1;
public float speedreduction = 1;
void Update()
{
Vector3 Adjustment = Vector3.zero;
if (transform.rigidbody.velocity.y > maxspeed)
{
Adjustment.y += -speedreduction;
}
if (transform.rigidbody.velocity.y < -maxspeed)
{
Adjustment.y += speedreduction;
}
rigidbody.velocity += Adjustment;
}
}
What does your existing script do? It shouldn't be very hard to hack that to only affect one axis!
– syclamoth