Created
January 16, 2015 08:25
-
-
Save uranuno/cd30838edf418e4a5ec2 to your computer and use it in GitHub Desktop.
反射をコードで書く実験
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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