Asteroids not moving down

hi everyone, in the following playcanvas editor project asteroids are functioning correctly.
i m trying re build the tutorial space shooter game from scratch.
here is the link : https://playcanvas.com/editor/scene/1229513

plz take a look what i m doing wrong.

Hi, @Umer_Younas,

Taking a look at your project the reason the asteroids are being destroyed so quickly is because the asteroids are moving vertically out of the bounds of your boundary box which has this script applied:

var DestroyByboundary = pc.createScript('destroyByboundary');

// initialize code called once per entity
DestroyByboundary.prototype.initialize = function() {
    this.entity.collision.on('triggerleave', this.onTriggerLeave, this);
};

DestroyByboundary.prototype.onTriggerLeave = function(entity) {
    entity.destroy();
};

This works if your asteroids only move parallel to the plane of the boundry box. You would want to lower the Y linear factor on all of the Asteroid Prefab Rigidbodies to 0, this will ensure that they do not float above or below the boundary box.

Also consider the questions below when seeking help. Getting all of this information together makes it much easier for forum users to help you:

What behavior am I trying to code?
What code have I tried in order to implement this behavior? (Include this code for others to help)
What behavior is my project exhibiting now?
What (if any) errors is my project generating?
How might others get to my project?
Why do I think the code I have used is not working? (Mostly optional, but can help with troubleshooting on your own)

I hope this is helpful!

2 Likes