Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CollisionDetection.js
- // Date : 05/12/2012
- // Time : 09:58
- // Author : Christopher Cullen
- // Description :
- // This function handles the collision between objects.
- // Declares the Variable "hitCount" as a Static variable of a type Int with a value of "0".
- static var hitCount : int = 0;
- // function Update()
- // This resets the objects X and Y position.
- // not the best way to do this but it is the only way i can get collision to work
- // without adding a ground plane.
- /*
- function Update()
- {
- transform.position.x = 0;
- transform.position.y = 0;
- }
- */
- // function OnCollisionEnter()
- // This function handles the collision.
- // If an object collides with this objects collider it will
- // count how ment times it has collided with the object.
- // Problems
- // 1) Hit's don't register unless one of the objects have a rigidbody.
- // possible fix's would be to set the X and Y position to zero on
- // very frame, but that wouldn't be ideal.
- function OnCollisionEnter(hit : Collision)
- {
- if(hit.gameObject.tag == "Player")
- {
- hitCount += 1;
- DoForce(200);
- }
- }
- // function DoForce()
- // This function handles the force applied to the object.
- function DoForce(force : float )
- {
- transform.rigidbody.AddForce(transform.position * force);
- }
Advertisement
Add Comment
Please, Sign In to add comment