- Home /
Dont transform.translate if it will collide with another object
How would I transform.translate down, and stop if it will collide with another object. I've tried onTriggerEnter(), and it does not seem to work. (as in, it's still moving)
#pragma strict
var a: Vector3;
var isFalling : boolean;
var fallingSpeed = 1;
var can$$anonymous$$ove : boolean = true;
function Start () {
collider.isTrigger = true;
collider.bounds.size.
}
function StartFall (speed : int) {
isFalling = true;
fallingSpeed = speed;
}
function EndFall () {
isFalling = false;
}
function Update () {
if(can$$anonymous$$ove == true) {
if(isFalling == true) {
transform.Translate(Vector3.down * Time.deltaTime * fallingSpeed);
}
}
}
function OnTriggerEnter(otherObject: Collider){
can$$anonymous$$ove = false;
}
function OnTriggerExit(otherObject : Collider) {
can$$anonymous$$ove = true;
}
Answer by fueldown · Jun 03, 2013 at 05:20 PM
check if either of the objects has rigidbody attached. OnTriggerEnter won't trigger if it doesn't.
Neither has a rigidbody attached, I dont want any of them to be falling. I'm making a tetris-like game.
Don't use built-in physics, then. Use specialised, simple physics.
Isnt that what I'm trying to do / doing?
$$anonymous$$aybe I should make a 3D array, ins$$anonymous$$d of detecting collisions.
OnTriggerEnter still uses built-in physics- I mean manually moving transforms around, and using whatever algorithm you like to manage potential collisions.
Any suggestions for any algorithms?
Should I try the 3D array?