Hey all! Some time ago Ractoc introduced me to Jmonkey and because i’m in between two sudies at the moment I finally have time to do something with it.
That being said; I would like to make a simple spaceship that can fly arround. The mouse would be used to rotate the ship up, down, left and right.
[java]public void onAnalog(String binding, float value, float tpf) {
if( binding.equals(“MouseXU”) ) {
red.rotate(0, rotateSpeedtpf, 0);
chaseCam.setDefaultHorizontalRotation(chaseCam.getHorizontalRotation() - rotateSpeedtpf);
} else if (binding.equals(“MouseXD”)){
red.rotate(0, -rotateSpeedtpf, 0);
chaseCam.setDefaultHorizontalRotation(chaseCam.getHorizontalRotation() + rotateSpeedtpf);
chaseCam.setDragToRotate(false);
}
if(binding.equals(“MouseYU”)){
red.rotate(0,0,rotateSpeedtpf);
chaseCam.setDefaultVerticalRotation(chaseCam.getVerticalRotation() -rotateSpeedtpf);
}
if(binding.equals(“MouseYD”)){
red.rotate(0,0,-rotateSpeedtpf);
chaseCam.setDefaultVerticalRotation(chaseCam.getVerticalRotation() +rotateSpeedtpf);
}
}[/java]
This only seems to work if I only enable either x direction or Y direction. If i enable both it starts spinning in a strange way.
Might help if you explain how you define “strange”. I’d also perhaps consider doing it a bit differently. Instead of having the mouse control the ship have the mouse move a point that the ship is trying to get too and have your ship object calculate it’s own way there instead. That would provide a bit of a muted movement more like you would with a real ship I feel.
Actually I would go even further than that, let the ship be a physical object, and steer it by adding force /torque, make it more human friendly by adding a dampening to angular and linear movement.
The box i used for testing these controls seems to be spinning alot, and I don’t seem to find a pattern in it.
I’ve thought about doing it with force, torque and dampening, but i couldn’t find a good example of how this could be done. In some older forum topics they point to the hovertank example, but that one works with a vehicle and wheels. Are there any good examples of this being done with a aircraft/spaceship?
Well there’s Urban Galaxy that’s done a spacey game (well ok more Fifth Element Taxi Cabs meets BattleStar Galactica but whatever). I’m still learning JME myself (although I’ve been here a while I haven’t done more than 50% of the tutorials and life has been haywire as of late) so I can’t really help beyond suggesting alternative methods to go down. Sorry.