Help with Flight Controls
by J.P. Berry · in Torque Game Engine · 10/16/2007 (4:36 pm) · 45 replies
Hey guys,
I am working on a space-sim type game and need to change the controls up a bit. I am using the Flight Game Example from Decane as my codebase.
The problem I have is that the Yaw and Roll are combined into one function in Torque. So when you turn left or right, you also roll over a little bit, depending on the variables set in your flight model. What I want to do is seperate Yaw and Roll. This way I can use the mouse to freely look around, not affecting roll at all. And then I would use the keys to control roll. Anyone have any ideas or can share their code?
I am working on a space-sim type game and need to change the controls up a bit. I am using the Flight Game Example from Decane as my codebase.
The problem I have is that the Yaw and Roll are combined into one function in Torque. So when you turn left or right, you also roll over a little bit, depending on the variables set in your flight model. What I want to do is seperate Yaw and Roll. This way I can use the mouse to freely look around, not affecting roll at all. And then I would use the keys to control roll. Anyone have any ideas or can share their code?
#2
10/24/2007 (8:32 am)
Oh the anticipation is killing me! :P
#3
10/24/2007 (8:37 am)
Hehe, where is James' code? :-))
#4
10/24/2007 (8:40 am)
How to do straffing would be cool too, so you can rudder around your target.
#5
the most recent FlyingVehicle resource.
Over the next few days I'll be working on getting this craft to operate like a ship in space.
Right now it auto-centers itself on the Z axis, which I need to stop it from doing, and the
banking while turning thing needs to be separated. (which I think is what you're after)
In the end I want the mouse controlling the targeting crosshair (or reticle), the A and D
keys controlling rotation left and right without roll or any forward movement, W and S
controlling rotation up and down without forward movement, Q and E to control roll.
Accelleration and decelleration will be a choice by the user of either mouse wheel or
+ and - keys.
How much progress I make on this will depend on which resources I can find to pick apart
and how much time I'm going to have to spend on our haunted house this week. :-)
Either way I'll post progress here if you want, and maybe we can turn this into a resource.
10/24/2007 (9:38 am)
I am also working on a space sim. I looked at the FGE but decided to usethe most recent FlyingVehicle resource.
Over the next few days I'll be working on getting this craft to operate like a ship in space.
Right now it auto-centers itself on the Z axis, which I need to stop it from doing, and the
banking while turning thing needs to be separated. (which I think is what you're after)
In the end I want the mouse controlling the targeting crosshair (or reticle), the A and D
keys controlling rotation left and right without roll or any forward movement, W and S
controlling rotation up and down without forward movement, Q and E to control roll.
Accelleration and decelleration will be a choice by the user of either mouse wheel or
+ and - keys.
How much progress I make on this will depend on which resources I can find to pick apart
and how much time I'm going to have to spend on our haunted house this week. :-)
Either way I'll post progress here if you want, and maybe we can turn this into a resource.
#6
My buddy Stefan Lundmark gave me the hint to use the player class as base and create a new vehicle class out of it. That's where I started yesterday my journey, not sure where it leads, but at least a promising idea. I'm not sure where it will go regarding the flight controls, not sure if I make it that differentiated like Kevin is doing (sounds great btw!) - will see.
What I'd like to ask you guys also is: Have you noticed that the flying vehicles always roll around a point that is not centered to the space ship/plane? It rolls always around a virtual point above the ship, so the rolling looks very unnatural. I digged into the code and found out that the center of mass node should be the point to rotate about, but regardless how I move that center of mass node in the DTS around, it will never rotate around the real axis of the space ship. Have you guys had any success modifying this or getting this better to work?
Btw: Regarding a reticle hud: I developed in the last days a full working client-side reticle hud GUI control. See a screenshot here:

It allows on the client-side to cylce with the mouse-wheel through all in the view-frustrum visible shapes, draw a rect around. Once one is selected, a lookup is done from client-side object id to server id and beeing sent then to the server. It allows a super nice missile target selection. Will post this as resource as soon as I cleaned it up a bit.
Anyway, let's keep posting here the progress we made! Good thread!
10/24/2007 (11:33 am)
Ahh, interesting thread. Seems we're all working on the same things :-) I restarted work on my game Subsonic and started working on a complete new flying vehicle class as the stock one is... uhmm... can be done hopefully better. I think we all know the flaws it has like the speed collision things etc. My buddy Stefan Lundmark gave me the hint to use the player class as base and create a new vehicle class out of it. That's where I started yesterday my journey, not sure where it leads, but at least a promising idea. I'm not sure where it will go regarding the flight controls, not sure if I make it that differentiated like Kevin is doing (sounds great btw!) - will see.
What I'd like to ask you guys also is: Have you noticed that the flying vehicles always roll around a point that is not centered to the space ship/plane? It rolls always around a virtual point above the ship, so the rolling looks very unnatural. I digged into the code and found out that the center of mass node should be the point to rotate about, but regardless how I move that center of mass node in the DTS around, it will never rotate around the real axis of the space ship. Have you guys had any success modifying this or getting this better to work?
Btw: Regarding a reticle hud: I developed in the last days a full working client-side reticle hud GUI control. See a screenshot here:

It allows on the client-side to cylce with the mouse-wheel through all in the view-frustrum visible shapes, draw a rect around. Once one is selected, a lookup is done from client-side object id to server id and beeing sent then to the server. It allows a super nice missile target selection. Will post this as resource as soon as I cleaned it up a bit.
Anyway, let's keep posting here the progress we made! Good thread!
#7
10/24/2007 (11:39 am)
@Kevin: Btw: which latest flying vehicle resource do you mean? Do you have a link for me?
#8
It was the flyingvehicle resource posted in 2004.
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5071
I've had success with eliminating the auto-center by commenting out the 2 lines in flyingvehicle.cc
that refer to the Gyroscope. A better alternative may be to create a variable to expose to script
so that the gyro can be turned off and on depending on the mission.
@Martin, your reticle is very close to what I'm after.
10/24/2007 (1:15 pm)
Ok, I must have been thinking of something else..It was the flyingvehicle resource posted in 2004.
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5071
I've had success with eliminating the auto-center by commenting out the 2 lines in flyingvehicle.cc
that refer to the Gyroscope. A better alternative may be to create a variable to expose to script
so that the gyro can be turned off and on depending on the mission.
@Martin, your reticle is very close to what I'm after.
#9
@Martin, the fact that the ships do not roll around the actual node on the model was one of the first things I noticed with the plane. Even when I moved the mass node to the wing it still rolled the same way. Maybe Kevin's fix makes it roll properly to the center? Barrel rolls just arent the same when you're rolling at such a wide radius. Anyways, the target reticule looks great, will definitely save a lot of people some time having to modify the existing resources. Keep up the great work.
@Kevin, if you haven't already, check out the Dynamic Gravity resource here. I would implement that first before tweaking your flight controls too much. My game goes from Zero Gravity back to Earth's Gravity in different missions, and the flight controls are actually a little different between the two. Things like rolling and the Gyroscope effect are affected pretty well. When you commented out the gyroscope code, did that mess with any of your flight behavior? Alternatively there is a line in your flyingvehicle.cs script like this : rollForce = 0; // Auto-roll (self-correction to right you after you roll/invert) and a couple of others that you can modify in script.
Also, if you're doing a space sim, you can use the precipitation feature to create a really nice stardust field. Just use a nice dust texture and set the gravity to 0 so they do not move. It makes for a really great effect when you're jetting around, giving a nice sensation of achieving acceleration.
Just for product promotion :P, here is a screenie of what I accomplished the first day of purchasing FGE, just a gravity mod, skysphere, stars, and some other resources found right here on GG. Pretty fun to play with, and making skyspheres is quite rewarding. ( though the screenie is not own my skyshpere)
10/25/2007 (5:38 pm)
What I have been trying to do is basically duplicate the flight model, or at least parts of it.. What I want to end up with, is variables like steeringRollForce = 0; and steeringRollForce1 = 8; . That way I can assign my turnleft /turnright functions to the steeringRollForce = 8;, and assign my newly created moveleft/moveright function to the SteeringRollForce=0 portion. Its an ugly way of doing it, duplicating instead of seperating, but it should work. I'll see what I can get done tonight.@Martin, the fact that the ships do not roll around the actual node on the model was one of the first things I noticed with the plane. Even when I moved the mass node to the wing it still rolled the same way. Maybe Kevin's fix makes it roll properly to the center? Barrel rolls just arent the same when you're rolling at such a wide radius. Anyways, the target reticule looks great, will definitely save a lot of people some time having to modify the existing resources. Keep up the great work.
@Kevin, if you haven't already, check out the Dynamic Gravity resource here. I would implement that first before tweaking your flight controls too much. My game goes from Zero Gravity back to Earth's Gravity in different missions, and the flight controls are actually a little different between the two. Things like rolling and the Gyroscope effect are affected pretty well. When you commented out the gyroscope code, did that mess with any of your flight behavior? Alternatively there is a line in your flyingvehicle.cs script like this : rollForce = 0; // Auto-roll (self-correction to right you after you roll/invert) and a couple of others that you can modify in script.
Also, if you're doing a space sim, you can use the precipitation feature to create a really nice stardust field. Just use a nice dust texture and set the gravity to 0 so they do not move. It makes for a really great effect when you're jetting around, giving a nice sensation of achieving acceleration.
Just for product promotion :P, here is a screenie of what I accomplished the first day of purchasing FGE, just a gravity mod, skysphere, stars, and some other resources found right here on GG. Pretty fun to play with, and making skyspheres is quite rewarding. ( though the screenie is not own my skyshpere)
#10
Nice screenie. I'm going to have to do that skysphere resource too. How hard is it to make
the graphics for the sphere?
10/25/2007 (6:03 pm)
Maybe I should start over with the FGE, then add some of this other stuff.Nice screenie. I'm going to have to do that skysphere resource too. How hard is it to make
the graphics for the sphere?
#11
Any way I can get you to post the code for the reticle, or email me a copy?? ;-)
10/25/2007 (6:04 pm)
@Martin,Any way I can get you to post the code for the reticle, or email me a copy?? ;-)
#12
10/25/2007 (7:21 pm)
I'm not into flight-sim stuff, sorry guys, but just a thought - could rotation be around the "cam" point? At least its sounds like "logical" :) Or maybe it's turning around the bounds center (nor origin)? Good luck with source-hashing :)
#13
complete with more features that I really wanted in the first place. (i.e. Radar,
Music in game, Advanced Camera) The ship seems more stable too. Just have
to make some adjustments to calm it down so I don't end up doing backflips.
Here's a current screenie just for fun. Haven't done much with it yet.

It's currently straffing left and right with the A and D keys. I want to turn that
into a pivot left and right.
I've implemented the Dynamic Gravity (updated for 1.5.2) resource from here.
That has helped some. The Scout ship must be tied into the FlyingVehicle.cc
instead of the AIFlyingVehicle.cc because there is no gravity modifier in the AIFlyingVehicle
files, yet the gravity change affected the scout ship anyway.
10/26/2007 (2:57 pm)
Ok, got the Flight Game Example loaded and now that I've seen it, it's morecomplete with more features that I really wanted in the first place. (i.e. Radar,
Music in game, Advanced Camera) The ship seems more stable too. Just have
to make some adjustments to calm it down so I don't end up doing backflips.
Here's a current screenie just for fun. Haven't done much with it yet.

It's currently straffing left and right with the A and D keys. I want to turn that
into a pivot left and right.
I've implemented the Dynamic Gravity (updated for 1.5.2) resource from here.
That has helped some. The Scout ship must be tied into the FlyingVehicle.cc
instead of the AIFlyingVehicle.cc because there is no gravity modifier in the AIFlyingVehicle
files, yet the gravity change affected the scout ship anyway.
#14
@Kevin: Give me a few days to clean up some stuff, then you'll get the stuff. I have some free time this weekend to actually do it. I'm going to make a public code resource out of it together with the necessary script changes and also put it into the FGE.
@bank: In theory yes, but the (first person) cam node is not in the center of the ship and the third person cam node not too, so rotating around the cam node would get some wired turning as it is now rotating around an arbitrary pivot point slightly above the ship. Ships usually turn around their mass center to get a more "natural" look. Btw. can there be a "natural look" with space ships? :-)
@J.P.: Yeah, that wrong turning sucks really. I'm going to spend more time on trying to find this little bugger in the next days. Hopefully I find something, I'm not the biggest physics expert on earth.. :-) Let's see what comes out. But I'm really astonished every time about what people do with the FGE. Esp. in your case that nice screenie with just 1 day of work. Super! :-)
10/27/2007 (3:21 am)
Interesting thread! Interesting screenies too. Like to see more. :-)@Kevin: Give me a few days to clean up some stuff, then you'll get the stuff. I have some free time this weekend to actually do it. I'm going to make a public code resource out of it together with the necessary script changes and also put it into the FGE.
@bank: In theory yes, but the (first person) cam node is not in the center of the ship and the third person cam node not too, so rotating around the cam node would get some wired turning as it is now rotating around an arbitrary pivot point slightly above the ship. Ships usually turn around their mass center to get a more "natural" look. Btw. can there be a "natural look" with space ships? :-)
@J.P.: Yeah, that wrong turning sucks really. I'm going to spend more time on trying to find this little bugger in the next days. Hopefully I find something, I'm not the biggest physics expert on earth.. :-) Let's see what comes out. But I'm really astonished every time about what people do with the FGE. Esp. in your case that nice screenie with just 1 day of work. Super! :-)
#15
@Kevin: Nice idea with the semi-transparent radar at the top left. Good idea!
10/27/2007 (3:23 am)
Ah, forgot to write: @Kevin: Nice idea with the semi-transparent radar at the top left. Good idea!
#16
a unmodified base of code and added all the resources from the docs. That included
the Advanced Camera, the Radar, the VMPlayer, and finally the FGE code itself. Then
dropped the AI for the purposes of this particular mission and popped into a mission
I made a few days ago. Oh, and I also added the Dynamic Gravity resource, so now
when you stop the ship doesn't move.
I was actually planning on bringing the radar down to middle center and building a
HUD around it for other stuff. It will probably end up semi-transparent green or grey,
but you're right. It does look pretty cool.. Thanks. :-)
10/28/2007 (8:46 am)
LOL... That was actually untouched from the installation of the FGE. I started witha unmodified base of code and added all the resources from the docs. That included
the Advanced Camera, the Radar, the VMPlayer, and finally the FGE code itself. Then
dropped the AI for the purposes of this particular mission and popped into a mission
I made a few days ago. Oh, and I also added the Dynamic Gravity resource, so now
when you stop the ship doesn't move.
I was actually planning on bringing the radar down to middle center and building a
HUD around it for other stuff. It will probably end up semi-transparent green or grey,
but you're right. It does look pretty cool.. Thanks. :-)
#17
Here's a little screenie from the Reticle HUD in the FGE:
11/02/2007 (9:14 am)
@Kevin: The reticle resources is close to release. FGE customers will get it latest this weekend and I will publish it also as public resource. Code is still somewhat unoptimized, but I think I work out the little flaws soon. Here's a little screenie from the Reticle HUD in the FGE:
#18
A simple switch would work nicely, say " targetingReticule = 1; ", that way we could switch it on and off, depending on vehicle, ammo type, etc. Just a thought..
11/02/2007 (11:00 am)
Great looking reticule. Just curious, does it work when you are both a character and a vehicle? Or just when you are in a vehicle? I set up the flight example so that you start as the Orc player, and you can then mountand unmount flying vehicles using the enter key. It actually took a little while to set it up this way. Anyways, it would be a nice feature if the reticule only kicked on when you entered the ship, but that's just my personal gametype :P.A simple switch would work nicely, say " targetingReticule = 1; ", that way we could switch it on and off, depending on vehicle, ammo type, etc. Just a thought..
#19
It depends on the weapon you select if the reticle is visible. Means, the server is controlling whether the player has the reticle showing up at the client or not. Basically there is in each weapon image a flag indicating that this is a weapon needing a reticle gui and when the player switches weapons, the weapon.cs onUse code checks whether this flag is set and sends a command to the client to enable the reticle hud.
The TGE version is already completed and I try now to get a TGEA version going somehow. The gui control has some config params like if you want to use a rectangle around the shape or only the corners, setting the normal/highlight color etc.
Here's a little video (10 MB) showing the switch to the homing missile, scrolling through the available targets in the view frustrum and fire the missile then.
So to answer your question, yes, it's possible to have the reticle only in the vehicle. You could do an additional if/else check for the reticle showing up only in vehicles or have a special weapon only for the vehicle that uses the reticle.
11/02/2007 (11:18 am)
Hehe, yes J.P., it is already that simple, good guess! :-) It depends on the weapon you select if the reticle is visible. Means, the server is controlling whether the player has the reticle showing up at the client or not. Basically there is in each weapon image a flag indicating that this is a weapon needing a reticle gui and when the player switches weapons, the weapon.cs onUse code checks whether this flag is set and sends a command to the client to enable the reticle hud.
The TGE version is already completed and I try now to get a TGEA version going somehow. The gui control has some config params like if you want to use a rectangle around the shape or only the corners, setting the normal/highlight color etc.
Here's a little video (10 MB) showing the switch to the homing missile, scrolling through the available targets in the view frustrum and fire the missile then.
So to answer your question, yes, it's possible to have the reticle only in the vehicle. You could do an additional if/else check for the reticle showing up only in vehicles or have a special weapon only for the vehicle that uses the reticle.
#20
11/02/2007 (11:25 am)
Forgot to post: That's how easy it is to turn on/off the reticle hud. So you could turn it on or off anytime in your code, J.P.commandToClient(%obj.client, 'SwitchReticleHUD', 1); // turn reticle hud on at client commandToClient(%obj.client, 'SwitchReticleHUD', 0); // turn reticle hud off at client
Torque Owner James Laker (BurNinG)