Skip to content

Instantly share code, notes, and snippets.

@uranuno
Created January 16, 2015 08:25
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 uranuno/cd30838edf418e4a5ec2 to your computer and use it in GitHub Desktop.
Save uranuno/cd30838edf418e4a5ec2 to your computer and use it in GitHub Desktop.
反射をコードで書く実験
using UnityEngine;
using System.Collections;
public class Reflect : MonoBehaviour {
public float power = 10f;
void OnCollisionEnter(Collision collision) {
Vector3 diff = collision.relativeVelocity;
if(diff != Vector3.zero) {
Vector3 reflectForce = Vector3.Reflect(diff, collision.contacts[0].normal);
collision.rigidbody.AddForce(reflectForce.normalized * power, ForceMode.Impulse);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment