Coppercube API Documentation
Class AnimatorCollisionResponse
Scene node animator making SceneNodes move using autoamtic collision detection and response
Extends
Animator.
Class Overview
AnimatorCollisionResponse(radius, gravity, translation, world, slidingspeed)
Special scene node animator for doing automatic collision detection and response.
This SceneNode animator can be attached to any single SceneNode and will then prevent it from moving through specified collision geometry (e.g. walls and floors of the) world, as well as having it fall under gravity. This animator provides a simple implementation of first person shooter cameras. Attach it to a camera, and the camera will behave as the player control in a first person shooter game: The camera stops and slides at walls, walks up stairs, falls down if there is no floor under it, and so on.
The animator will treat any change in the position of its target scene node as movement, including changing the .Pos attribute, as movement. If you want to teleport the target scene node manually to a location without it being effected by collision geometry, then call reset() after changing the position of the node.
The algorithm used here is a very fast but simple one. Sometimes, it is possible to get stuck in the geometry when moving. To prevent this, always place the object at a position so that the yellow ellipsoid isn't colliding with a wall in the beginning, so that it is not stuck.
If the object gets stuck during movement, then the problem might be the 3d collision mesh: One needs to be a bit careful when modelling the static geometry the object collides against. The geometry should be closed, and there should not be any one sided polygons sticking out anywhere, those are usually the places where one gets stuck.
Also, if the points of vertices which should be together are not exactly at the same point could cause problems. If the used 3d modelling software supports a feature like 'Merge Points' to make neighbour vertices be exactly at the same place, it is recommended to do this, it also usually helps.
This SceneNode animator can be attached to any single SceneNode and will then prevent it from moving through specified collision geometry (e.g. walls and floors of the) world, as well as having it fall under gravity. This animator provides a simple implementation of first person shooter cameras. Attach it to a camera, and the camera will behave as the player control in a first person shooter game: The camera stops and slides at walls, walks up stairs, falls down if there is no floor under it, and so on.
The animator will treat any change in the position of its target scene node as movement, including changing the .Pos attribute, as movement. If you want to teleport the target scene node manually to a location without it being effected by collision geometry, then call reset() after changing the position of the node.
The algorithm used here is a very fast but simple one. Sometimes, it is possible to get stuck in the geometry when moving. To prevent this, always place the object at a position so that the yellow ellipsoid isn't colliding with a wall in the beginning, so that it is not stuck.
If the object gets stuck during movement, then the problem might be the 3d collision mesh: One needs to be a bit careful when modelling the static geometry the object collides against. The geometry should be closed, and there should not be any one sided polygons sticking out anywhere, those are usually the places where one gets stuck.
Also, if the points of vertices which should be together are not exactly at the same point could cause problems. If the used 3d modelling software supports a feature like 'Merge Points' to make neighbour vertices be exactly at the same place, it is recommended to do this, it also usually helps.
- Parameters:
- radius
- {Vect3d} 3d vector describing the radius of the scene node as ellipsoid.
- gravity
- {Vect3d} Sets the gravity of the environment. A good example value would be new Vect3d(0,-100.0,0) for letting gravity affect all object to fall down. For bigger gravity, make increase the length of the vector. You can disable gravity by setting it to (0,0,0);
- translation
- {Vect3d} Set translation of the collision ellipsoid. By default, the ellipsoid for collision detection is created around the center of the scene node, which means that the ellipsoid surrounds it completely. If this is not what you want, you may specify a translation for the ellipsoid.
- world
- Representing the world, the collision geometry, represented by a TriangleSelector.
- slidingspeed
- {Number} (optional) A very small value, set to 0.0005 for example. This affects how the ellipsoid is moved when colliding with a wall. Affects movement smoothness and friction. If set to a too big value, this will also may cause the ellipsoid to be stuck.
Method Attributes | Method Name and Description |
---|---|
animateNode(n, timeMs)
Animates the scene node it is attached to and returns true if scene node was modified.
|
|
Returns the vector representing the gravity of the environment
|
|
getType()
Returns the type of the animator.
|
|
getWorld()
Returns the triangle selector representing the world collision data
|
|
Returns if the scene node attached to this animator is currently falling
|
|
reset()
Resets the collision system.
|
|
setGravity(g)
Sets the gravity of the environment.
|
|
setWorld(selector)
Sets the triangle selector representing the world collision data
|
- Methods borrowed from class Animator:
- onKeyDown, onKeyUp, onMouseDown, onMouseMove, onMouseUp, onMouseWheel
Method Detail
animateNode(n, timeMs)
Animates the scene node it is attached to and returns true if scene node was modified.
- Parameters:
- n
- The Scene node which needs to be animated this frame.
- timeMs
- The time in milliseconds since the start of the scene.
getGravity()
Returns the vector representing the gravity of the environment
getType()
Returns the type of the animator.
For the AnimatorCollisionResponse, this will return 'collisionresponse'.
getWorld()
Returns the triangle selector representing the world collision data
isFalling()
Returns if the scene node attached to this animator is currently falling
reset()
Resets the collision system. Use this for example to make it possible to set a scene node postition
while moving through walls: Simply change the position of the scene node and call reset() to this
animator afterwards.
setGravity(g)
Sets the gravity of the environment. A good example value would be new Vect3d(0,-100.0,0) for letting gravity
affect all object to fall down. For bigger gravity, make increase the length of the vector.
param g {Vect3d} gravity vector
- Parameters:
- g
setWorld(selector)
Sets the triangle selector representing the world collision data
- Parameters:
- selector