relativeVelocity
The relative linear velocity of the two colliding objects (Read Only).
Read time 1 minuteLast updated 9 days ago
Definition
- Type: Property
- Namespace: UnityEngine
- Assembly: UnityEngine.Physics2DModule
public Vector2 relativeVelocity { get; }
Examples
// Play a sound when we hit an object with a big velocityusing UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ AudioSource audioSource; void Start() { audioSource = GetComponent<AudioSource>(); } void OnCollisionEnter2D(Collision2D collision) { if (collision.relativeVelocity.magnitude > 2) audioSource.Play(); }}