- Home /
Collision problems?
Hello i have this script that works great but first when i collide with this object i want the script to run and keep going even if the player is mot colliding with it any more? how can i do this here is my code. also the 2 objects have colliders on them and they repel each other how can i get this to work?
#pragma strict
var target : Transform;
var smoothTime = 0.3;
private var thisTransform : Transform;
private var velocity : Vector3;
var offsetAmountx : float = 10.00;
var offsetAmounty : float = 10.00;
function Start()
{
thisTransform = transform;
}
function OnCollisionEnter(collision : Collision) { // Rotate the object so that the y-axis faces along the normal of the surface
var contact : ContactPoint = collision.contacts[0];
thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x,
target.position.x +offsetAmountx,velocity.x, smoothTime);
thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y,
target.position.y +offsetAmounty,velocity.y, smoothTime);
}
Answer by Fattie · Jun 23, 2012 at 08:08 PM
Whatever it is you want it to "keep doing"
write a NEW script called "myHappyBehaviour"
in that behaviour, make it do .. whatever you want. the thing you want it to "keep doing"
Now, very simply ... when the collision happens ... just ...
turn on the script myHappyBehaviour
Simple huh?
When for some reason you want the object to STOP doing that thing, just turn off that component.
Always remember: life can be incredibly easy. Unless you want to make it hard!
Your answer

Follow this Question
Related Questions
A node in a childnode? 1 Answer
Raycasting to make Buildings Clickable 1 Answer
physics.OverlapSphere colliders 1 Answer
Collision between two sphere game object 1 Answer
Getting 2 colliders, prefab and clone need help please. 0 Answers