标签:
using UnityEngine; using System.Collections; public class co : MonoBehaviour { private Collider collider; private ContactPoint contacts; [SerializeField] private Transform explosionPrefab; // Use this for initialization void Start () { } // Update is called once per frame void Update () { } void OnCollisionStay(Collision collision) { collision.rigidbody.useGravity = false; //collision.rigidbody.velocity =new Vector3(0, 0, 0); Debug.Log("------"); foreach(ContactPoint contacts in collision.contacts){ //Debug.DrawRay(contacts.point, contacts.normal, Color.red,2); //Debug.Log("contacts.normal:" + contacts.normal); //collision.transform.eulerAngles = contacts.normal; collision.transform.rotation = Quaternion.FromToRotation(Vector3.up, contacts.normal); collision.rigidbody.AddForce(contacts.normal * 0.2f); collision.rigidbody.AddForce(collision.transform.forward * 1f); Debug.DrawRay(contacts.point,collision.transform.forward , Color.green, 2); Debug.DrawRay(contacts.point, contacts.normal, Color.red, 2); } } void OnCollisionEnter(Collision collision) { ContactPoint contact = collision.contacts[0]; Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal); Vector3 pos = contact.point; //Instantiate(explosionPrefab, pos, rot); //collision.rigidbody.useGravity = false; //collision.rigidbody.AddForce(transform.forward*-0.2f); } }
标签:
原文地址:http://www.cnblogs.com/sy88/p/4299829.html