Tilting a spaceship without altering it's height

Blitz3D Forums/Blitz3D Beginners Area/Tilting a spaceship without altering it's height

Farflame(Posted 2008) [#1]
I'm just fiddling around with some basic 3D and to get me started I'm doing a simple overhead shooter with spaceships. Since it's overhead, I want them to maintain a certain height but when they turn, I want them to tilt from side to side. Unfortunately, when I do that, they also change their height. I'm using.......

TurnEntity SpaceShip\Entity,0,Tilt#,0

To tilt them.

And......

MoveEntity SpaceShip\Entity,0,0,SpaceShip\Speed#

To move them forwards.

I've tried simply resetting their height after the movement, but then they start tilting forwards or backwards on strange angles.

What am I doing wrong?


Santiworld(Posted 2008) [#2]
the enitityship is parent to other object?


GfK(Posted 2008) [#3]
Parent the ship to a pivot.

When the ship rolls left/right, apply the rotation to the ship. When you want to turn left/right, apply the rotation to the pivot.


Stevie G(Posted 2008) [#4]
Make sure you change the roll angle rather than yaw angle for titling. Also, apply the forward movement to the pivot, rather than the ship.


Farflame(Posted 2008) [#5]
Hmm, still not quite got it. Been tinkering away with pivots for a while but I'm still getting some odd results. I'm moving/tilting the ships like this.....

		MoveEntity SpaceShip\Pivot,0,0,SpaceShip\Speed#
		
		RotateEntity SpaceShip\Ship,0,0,SpaceShip\Bank
		
		TurnAmount#=SpaceShip\Bank
		TurnAmount#=TurnAmount#/100
		TurnEntity SpaceShip\Pivot,0,TurnAmount#,0


But they're not turning correctly. Is there a tutorial on pivots anywhere?


GfK(Posted 2008) [#6]
Looks right to me.

Have you placed the pivot and the spaceship at the exact same location? For debugging, I used to change CreatePivot() to CreateSphere(). That way you can see exactly where the pivot is at. In your case you might need to EntityAlpha ship,0.5 in order to see the pivot (as it will probably be inside the ship if its in the right place).


Yan(Posted 2008) [#7]
Just use TranslateEntity.


Ross C(Posted 2008) [#8]
Don't use turnentity.

Use:

RotateEntity entity, EntityPitch(entity,true),EntityYaw(entity,true), EntityRoll(entity,true)


And just add on what you need to turn. If you want to add one to the x axis rotation, then:

RotateEntity entity, EntityPitch(entity,true)+1,EntityYaw(entity,true), EntityRoll(entity,true)


Turnentity is usually the wrong command to use when rotating on multiple axis.

You could wrap the above in a function:

Function Turn_Entity(entity,x#,y#,z#,global = false)
   RotateEntity entity, EntityPitch(entity,true)+x,EntityYaw(entity,true)+y, EntityRoll(entity,true)+z,global
End Function


Then just call:

Turn_Entity(entity,10,0,0)



Stevie G(Posted 2008) [#9]
I don't agree. If he's only turning on the pivot on yaw axis there is nothing wrong with using turnentity. Turn entity uses quarternions internally, whereas rotateentity does not so introduces the dreaded gimbal lock.


Farflame(Posted 2008) [#10]
Thanks guys, sorted this problem at least and they're turning and banking correctly now. The problem seemed to be when I used the Entityparent command - if I did it before positioning the pivot and ship they weren't stuck together correctly. I had to create both, position them and align them correctly and then use the EntityParent command - I wasn't aware that it was that complicated and assumed originally that using the command would stick them together itself. I've run into another problem but will open a new thread as it's not related to this.