Skip to content

Instantly share code, notes, and snippets.

@JPBotelho
Created November 25, 2018 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JPBotelho/23e8050d349dd5e6634645543876427f to your computer and use it in GitHub Desktop.
Save JPBotelho/23e8050d349dd5e6634645543876427f to your computer and use it in GitHub Desktop.
Ship Bounce
private void OnTriggerEnter(Collider other)
{
Debug.Log("Collided with " + other.transform.name);
Vector3 rbVelocity = Actor.RigidbodyComp.velocity;
Vector3 direction = transform.position - GetComponent<Collider>().transform.position;
direction.Normalize();
Actor.RigidbodyComp.velocity = Vector3.zero;
Actor.RigidbodyComp.AddForce(-rbVelocity.normalized * force, ForceMode.Impulse);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment