- Home /
Question by
CaptainBoggle · Feb 20, 2019 at 06:22 AM ·
movementplayerdetectionaxes
How to detect if player stops moving along Y axis
Hey, I am trying to figure out how to detect when the player has 0 velocity along the y axis only (eg. they land on a platform), and then destroy the player. So far I have only been able to find scripts that detect all player movement, but I really need it to just detect the Y axis specifically. Thanks for the help!
Comment
Assu$$anonymous$$g the player has a rigidbdy
public Rigidbody body;
void Awake()
{
body = GetComponent<Rigidbody>();
}
void Update()
{
if (body)
{
Vector3 velocity = body.velocity;
Debug.Log("Y Axis Velocity is " + velocity.y);
}
}
Unless you're doing Root $$anonymous$$otion from an Animation, in which case it's different but still easy to acquire. Especially if you're simulating root motion yourself.
Answer by mlnczk · Feb 20, 2019 at 10:21 AM
Rigidbody rb;
private void Awake(){
rb = GetComponent<Rigidbody>();
}
private void Update(){
if(rb.velocity.y < 0){
// do your code
}
}