Game Development Reference
In-Depth Information
if(!collision){
break;
}
angle += FastMath.QUARTER_PI;
}
private boolean checkCollision(Ray r){
CollisionResults collResuls = new
CollisionResults();
world.collideWith(r, collResuls);
if(collResuls.size() > 0 &&
r.getOrigin().distance(collResuls.getClosestCollision().getContactPoint())
> okDistance){
return true;
}
return false;
}
5. In the last step in this method, we call the animation manager and tell it to play or
stop playing the near-edge animation, as shown in the following code. We do this
based on whether all the collisions have been detected or not, making sure we
only send any change in state:
if(!collision && !nearEdge){
nearEdge = true;
spatial.getControl(AnimationManagerControl.class).onAction("NearEdge",
true, 0);
} else if(collision && nearEdge){
nearEdge = false;
spatial.getControl(AnimationManagerControl.class).onAction("NearEdge",
false, 0);
}
6. Switching to our animation manager class, we modify it accordingly. The state is
stored here so it can be used to see what other animations are allowed to be
played, as follows:
if (binding.equals("NearEdge")) {
nearEdge = value;
if(nearEdge){
setAnimation(Animation.Jumping, Channel.Upper);
Search WWH ::




Custom Search