I’ve been looking for sample code to see how people have set up a game with Diablo-style camera and controls. I’ve been trying to set up such a thing, but I’m running into issues that I’m unsure about. I have a ChaseCamera that follows the player and I’m able to get a reference to the Geometry the player clicks on via collision detection. I’m having a hard time turning the player to face the click and then walk to the collision contact point.
Has anyone seen any sample code to set this up or can you offer me any tips on how this should work?
This may help with the camera controls:
Easiest way to look at a point is Spatial.lookAt ()
To move in that direction do:
[Java]Vector direction = Spatial.getlocalrotation ().mult (Vector3f.UNIT_Z;[/java]
(these both assume that the model is z forward:
Thanks a lot for that, it is extremely helpful. I’ve got the character moving towards a clicked point. However, he moves backwards. I am using the Ninja model that comes bundled with jme. Does that mean that this model is not “z forward”? How should I account for that?
Lastly, the character simply moves in a straight line to the clicked point, regardless of its height or the terrain. So, he floats a lot. Should I be using Bullet to get him to stick to the terrain while moving?
I must admit, I’ve coded myself into a corner. I’ve been manipulating the player as a Spatial and that has worked fine except that they would not walk along the ground correctly or otherwise have any physics in the scene. I probably should have been using a CharacterControl, but I can’t see how to manipulate a character control in the same way I’d been manipulating the Spatial (meaning lookAt() and movement are no longer working once the player Spatial has a CharacterControl attached to it).
Any advice on how to get a Spatial with an attached CharacterControl to be controlled in a Diablo-style while still having all the benefits of the physics engine?
I think I’ve got something that might be workable. Once I found the methods player.setWalkDirection and player.setViewDirection, it became much more clear. I’ve got my very own Sinbad moving around and not going through walls. Now I just need to figure out how to make him actually do a walking animation, but that’s another topic =)