1 decade ago
by Aenopix
I still dont know how collisions work. How i can manage to make if an enemy collides with something (player or a waypoint), an event happen. Like go in a specific direction, etc.
Thanks
1 decade ago
by Arantor
When an object collides with another, its check() method is called and you can do something in there to figure out what should happen.
Note that both objects have check() methods so you can tie behaviour to specific objects rather than have the player's object have lots and lots of behaviours defined.
It might be worth your while looking at the video explaining how Weltmeister (level editor) works because there's behaviour explained in there for triggers (entities that exist solely to track collision and do something on colliding, e.g. in Biolab Disaster, the earthquakes, the water and level changes are all handled as entities triggering things happening), and you'll also find code in the 'entity pack' on your download page that was taken from Biolab Disaster showing how these things work.
Read through the
documentation. You'll typically want to use
collideWith() vs.
check().
For example, let's take the Pong sample. If you're a Puck, you'll want to check for a collision with the Paddle, and if you collide with Paddle, reverse the Puck's direction so that it now goes the other way. You do so in the Puck's collideWith():
collideWith: function( other, axis ){
if( other instanceof EntityPaddle ){
//this will reverse the puck's direction
this.vel.x = -this.vel.x;
}
}
1 decade ago
by Arantor
That works too... it's all down to exactly what you're trying to do as to how best to do it. Sometimes what I've said will work better, sometimes what quidmonkey has said will work better.
Page 1 of 1
« first
« previous
next ›
last »