I am trying to find a way to simulate rise of an object up a ramp, dome or other spatial object without using physics.
I have been able to use the Collision Results to determine if there is an intersection of the meshes. I am just unable to identify the height of the location mesh intersection points. This information would give me a height that I can raise my moving object.
I suppose you could technically use a ray or several underneath your object to determine what is under it and move it based on the distance to the surface hit by the ray but this all sort of depends a bit on what the object you’re moving looks like and what effect you’re trying to achieve.
When the player is intersecting the object I get collision results, however the contact point is null and the distance is 0.
If the player is not intersecting the object I get no collision results.
At this point I need to find the most accurate height that I need to move the player.
I would like for the player to move relatively smooth up a ramp or over a shallow dome.
Thank you for any help you can give.
void moveBody(Player player, float x, float y, boolean queue) {
if (performer.isDisposed())
return;
checkValidQueueUse("movePlayer ", queue);
//************Collision Detection Begin
float height = 0;
float newHeight = 0;
BoundingVolume volume = null;
CollisionResults results = new CollisionResults();
if (TEST_COLLISION){
for (Prop prop:propList){ //Traverse through list of Collidable objects
results.clear();
prop.getNode().updateModelBound(); //Update the Model Bounds for the object
player.getBody().updateModelBound(); //Update the Model Bounds for the Player
raverse through the object node for any children and test for collision
for (Spatial child :prop.getNode().getChildren()){
child.collideWith(performer.getBody(), results);
if(results.size()>0){
CollisionResult closest = results.getClosestCollision();
System.out.println("What was hit? " + closest.getGeometry().getName() );
System.out.println("Where was it hit? " + closest.getContactPoint() );
System.out.println("Distance? " + closest.getDistance() );
// Get the bounds of the object node to find the center and derive a height of the object
volume = prop.getNode().getWorldBound();
float center = volume.getCenter().y;
height = center*2f;
if (height>newHeight)
newHeight = height;
}
}
}
}
//************ Collision Detection End
moveObjectInScene(performer.getBody(), x, y, newHeight, queue);
}
Yeah, spatial → spatial collisions aren’t going to be accurate enough to do what you want. First of all, they are only doing bounding shape collisions. Second, you won’t get a contact point and stuff.
…50% of a physics engine is collision detection. It’s a big deal and not something that can be easily built into a scene graph.
So as the other person stated, you probably want to use Ray → Spatial collision instead if you don’t want to use real physics collisions. Ray → spatial collisions will give you contact point, penetration, normal, etc… all of which can be used to move up a ramp.