# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### DarkBASIC Discussion / Free Flight Control Issues

Message
Posted: 4th Jul 2011 21:31
So I've been trying this thing from every angle and I must be missing something because it doesn't seem that hard.

I am working on a space dogfight type game which of course requires lots of twisting and turning. My problem is that when I become upside down, my X axis control gets inverted.

My relevant code is here:

Thanks!

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Posted: 5th Jul 2011 03:39
Typo mistake :

Should be :

Warning! May contain Nuts!
Posted: 5th Jul 2011 05:12
@BN2

DBC the easiest way to handle this type of control, in my opinion, is by using limb control where the base limb (or another) is considered a pivot object.

The pivot object is only rotated on the y axis, so it steers left or right. The aircraft will be a separate limb and will pivot on the X and z axes. You can of course hide the pivot object(limb).

This can be done with gluing an object but I recommend against that. You'll loose lighting control and position and rotation information as well as collision is basically useless.

Posted: 5th Jul 2011 09:49
Hmm interesting solution Latch. How would motion be controlled in this system? It seems that if you are rotating limbs then the MOVE OBJECT command would be rendered useless.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Posted: 5th Jul 2011 13:44
Just reposition the object using Position Object obj,x,y,z but as well you can get the current position with Object Position X(obj), Object Position Y(obj). To add gravity just decrement the objects Y position and this will not affect your free flight control...

Warning! May contain Nuts!
Posted: 5th Jul 2011 14:50
I think you should be using the free flight rotation commands:
'turn', 'pitch' and 'roll' only, not 'rotate object'.

Posted: 6th Jul 2011 00:12
The problem with turn pitch and roll is that they give odd angle values. For instance, check the object's Y angle as you turn it. You will see that it goes from 0->90->0->-90 (I think, it may be 0->90 then switch to -90 and go to 0). When it stops increasing (or decreasing) you will notice that the Z and X angles get adjusted (for instance, both with become 180 when it first stops increasing).

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Posted: 6th Jul 2011 00:48 Edited at: 6th Jul 2011 01:17
Quote: "The problem with turn pitch and roll is that they give odd angle values.
"

This is a common problem when creating flight sims etc, there will be a solution, I'll have a look around and see if I can get any info on what developers do in this situation, I suppose you need the real world angles for hud dials, navigation etc?

EDIT: Had a quick look, I'm not sure there is a simple solution, some people use the limb method mentioned above. There are a couple of space games on the wip board, I would ask them what they do

Posted: 6th Jul 2011 01:58 Edited at: 6th Jul 2011 02:01
I don't understand the problem. I can't test it out but from rotating a pill box in my hand all the rotations seem correct even when rotation has occurred on multiple axes.
It seems to me that using a hidden limb as a pivot would produce very unrealistic movement, to turn an aircraft you roll to either side and adjust the pitch, turning with the rudder (Y axis) is more for fine tuning as I understand. Maybe I'm completely wrong I don't know, could you explain the effects rotation has on the craft at the moment?

I found this useful diagram of aircraft rotations

When I was looking at your code I simplified it a bit and changed the controls to what seems more natural/realistic. As I said above I'm not really sure what the problem is or how it manifests itself so I haven't changed how the code works.

Posted: 6th Jul 2011 03:44
When using the free flight controls on object the return value given by OBJECT ANGLE Y(OBJ) is messed up. It is an error in the software and not your code. There are ways around this but it does require a tad more code unless you can get away with not using the OBJECT ANGLE Y() function.

Warning! May contain Nuts!
Posted: 6th Jul 2011 05:35
@BN2

Quote: "Hmm interesting solution Latch. How would motion be controlled in this system? It seems that if you are rotating limbs then the MOVE OBJECT command would be rendered useless."

It depends on how you want the control of the craft to be.

I can mock up an example or two of what I was talking about with the limbs and such. Could you tell me the goal of what you are trying to achieve flight wise?

Is it a 3rd person view with the camera following the ship? When rolling (z rotation) should the ship stay in place and just roll or does it force a banking kind of thing?

In terms of y rotation, do you want that to control any banking? For example,the tighter the turn, the steeper the banking.

Is it a camera view from the cockpit?

Do you need the controls to "just work" or do you need to return specific angles?

The trouble with returning specific angles (euler angles) is that there are several combinations of rotations that can return a given orientation.

@Obese87
Quote: "It seems to me that using a hidden limb as a pivot would produce very unrealistic movement"

What makes it seem that way to you?

The pivot stands in as a constant frame of reference. It allows one to control world rotations and local rotations. Not using the built in commands this is handled with matrix and quaternion rotation maths in 3d. Limbs in DBC allow you to bypass the heavy math and use already built in methods to handle this.

For example, if you zrotate limb 1, you could y rotate the base limb and create a convincing banking movment for an aircraft. If you tried to ROLL and TURN an object, this wouldn't work.

Posted: 6th Jul 2011 16:16
Quote: "When using the free flight controls on object the return value given by OBJECT ANGLE Y(OBJ) is messed up. It is an error in the software and not your code. There are ways around this but it does require a tad more code unless you can get away with not using the OBJECT ANGLE Y() function."

I don't think its an error, its just the nature of how free flight rotation works, I think(although not tested) that the euler angles returned probably do represent the current orientation, although they look messed up.

Posted: 6th Jul 2011 22:17
@Latch
What I'm going for is space dogfight type system.

The camera is normally cockpit view, but can be moved back (the code isn't in my clipping because it doesn't really do much).

All specifics of movement and turn radius etc will be controlled by the components the player installs on the ship, but for now are just hard coded. There's no need for banking, I'll let the player roll and pitch if they want to bank their turns.

Motion is controlled by a throttle (in this case, the joystick Z axis).

I'll try out the limb rotation control and see if I can get something working.

@Obese
Essentially it ends up LOOKING correct, but the way it gets to the given orientation makes the individual angle values completely useless (since a single Y axis angle difference could result in a 180 degree difference on the X and Z angle values).

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Posted: 7th Jul 2011 05:10
@BN2
My suggestion was along the lines of a craft banking as it turns (in the air as opposed to space where it wouldn't bank) and staying on the same plane. In the case of free rotations on all axes, as Matty H. had suggested, PITCH, TURN and ROLL (in that order) may be what you are after for the control.

Are the returned angles needed?

Posted: 7th Jul 2011 09:37
Quote: " Are the returned angles needed?"

Strictly speaking, no not yet. However, I may need them later and I don't want to have this stay as a wrench in the system.

I actually am working on a way to rotate around the object's local X Y and Z Axes, it's a little buggy, but it's coming together (finally got it to stop 'exploding' and spinning the ship everywhere). Once I get it working, I'll pack it into useful functions and post them.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Posted: 8th Jul 2011 11:34
@BN2

Take a look at the following snippet. It uses pitch turn and roll to rotate the object independently on each axis. However, I am using a limb to repot on the object's world angles which may give you more desirable results. Unfortunately, through a glitch in DBC, the Z angle for a limb cannot be returned; though I just use the object's z angle which should suffice. UP DOWN for pitch LEFT RIGHT for turn 'Z' 'X' keys for roll: