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
Share
Go down
avatar
Member [Lv. 0]
Member [Lv. 0]
Posts : 1
Points : 1211
Rep : 0
Join date : 2015-03-31
View user profile

howto destroy boxes only with force not just touch

on Tue Apr 26, 2016 6:12 pm
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);
}
}
avatar
{SUPER MEMBER}-LV.4
{SUPER MEMBER}-LV.4
Posts : 53
Points : 1530
Rep : 11
Join date : 2015-01-18
Age : 41
Location : Italia
View user profile

Re: howto destroy boxes only with force not just touch

on Sun May 01, 2016 11:12 am
Use magnitude for destroy object

Code:
void OnCollisionEnter(Collision collision) {
    // apply collision damage
    if (collision.relativeVelocity.magnitude > 0.5) {
       Destroy(gameObject);
    }
Very Happy
{SUPER MEMBER}-LV.4
{SUPER MEMBER}-LV.4
Posts : 54
Points : 1910
Rep : -7
Join date : 2014-01-28
View user profile

Re: howto destroy boxes only with force not just touch

on Tue May 03, 2016 1:31 pm
http://renntekstudios.co.uk
Back to top
Permissions in this forum:
You cannot reply to topics in this forum