Game Development Reference
In-Depth Information
The following code attaches an event handler to a rigid body and simply logs the event
info. The
body
object holds the information of the other rigid body it collided with:
this.rigidBody.addEventListener(jigLib.JCollisionEvent.COLLISION,
function(event){
console.log(event);
//event.collisionBody
//event.collisionInfo
});
Revisiting the grenade and bullet actions
In this code packet, we will demonstrate how the grenade action should actually be
implemented. In the earlier code packet, the grenade motion was controlled by a set
of defined points transformed with the camera matrix. The solution is not perfect
because the length of the animation is limited and does not simulate the real-world
effect in instances such as when the object path was disrupted by another object.
So, let's first revisit our grenade code. Open the
Grenade.js
file from
primitive/
game
in your favorite editor. We will start with the initialization of the rigid body
(sphere) in the
Grenade
class and then apply an impulse in a specific direction, as
expressed in the following diagram:
F
The preceding diagram shows an impulse/force applied on the
y
axis and in the -Z
direction at the centroid of the cube's rigid body.