Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » HELP » Help (General) » howto destroy boxes only with force not just touch

howto destroy boxes only with force not just touch

View previous topic View next topic Go down  Message [Page 1 of 1]

petee1979


Member [Lv. 0]
Member [Lv. 0]
i am making a Mario styled game, I wrote a script so if I jump and hit a box it destroys but if I walk on top of the boxes as soon as I touch the box it also gets destroyed,
any ideas on how to make it so the box doesn't get destroyed if I walk ontop of it. cheers

this is my destroy script

var XPos : float = transform.position.x;
var YPos : float = transform.position.y;
var ZPos : float = transform.position.z;
var Waiting : float = 0.02;

function OnTriggerEnter (col : Collider) {

if (col.gameObject.tag == "Player") {
this.transform.position = Vector3(XPos, YPos+0.1, ZPos);
yieldWaitForSeconds(Waiting);
this.transform.position = Vector3(XPos, YPos+0.2, ZPos);
yieldWaitForSeconds(Waiting);
transform.GetComponent.<Collider>().isTrigger = false;
this.transform.position = Vector3(XPos, YPos+0.3, ZPos+0.5);
yieldWaitForSeconds(Waiting);
this.transform.position = Vector3(XPos, YPos+0.4, ZPos+1.0);
yieldWaitForSeconds(Waiting);
this.transform.position = Vector3(XPos, YPos-0.1, ZPos+1.5);
yieldWaitForSeconds(Waiting);
this.transform.position = Vector3(XPos, YPos-0.6, ZPos+2.0);
yieldWaitForSeconds(Waiting);
this.transform.position = Vector3(XPos, YPos-1.6, ZPos+2.0);
yieldWaitForSeconds(Waiting);
this.transform.position = Vector3(XPos, YPos-2.6, ZPos+2.0);
yieldWaitForSeconds(Waiting);
this.transform.position = Vector3(XPos, YPos-4.0, ZPos+2.0);
yieldWaitForSeconds(0.25);
transform.GetComponent.<Collider>().isTrigger = true;
Destroy(gameObject);
}
}

View user profile

PitbullM


Member [Lv. 3]
Member [Lv. 3]
Use magnitude for destroy object

Code:
void OnCollisionEnter(Collision collision) {
    // apply collision damage
    if (collision.relativeVelocity.magnitude > 0.5) {
       Destroy(gameObject);
    }
Very Happy

View user profile

jakeyiii


Member [Lv. 3]
Member [Lv. 3]
http://renntekstudios.co.uk

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum