3d asteroids movement?

Blitz3D Forums/Blitz3D Programming/3d asteroids movement?

Boiled Sweets(Posted 2006) [#1]
Hi,

has any one got or seen some basic code of how to move in 3d space a bit like a 3d asteroids? With nice momentum, drift etc?

There was something posted in the code archived titled 2d asteroids but it's a lot lacking.

Thanks.


Andy(Posted 2006) [#2]
http://www.blitzbasic.com/codearcs/codearcs.php?code=1547


Andy


Boiled Sweets(Posted 2006) [#3]
Yeah thats the one I was saying is not so good.


Andy(Posted 2006) [#4]
>Yeah thats the one I was saying is not so good.

Thank you, but you asked for

"how to move in 3d space a bit like a 3d asteroids? With nice momentum, drift etc?"

If that doesn't suit your needs, what more do you need?


Andy


Stevie G(Posted 2006) [#5]
Is this any good? I have included rotational momentum but could be adapted to suit your needs ...

Graphics3D 640,480,16,1

Const Upkey = 200
Const DownKey = 208
Const LeftKey = 203
Const Rightkey = 205

Global Camera = CreateCamera()
PositionEntity Camera,0,0,-150

Type Player
	Field Model
	Field SpeedX#
	Field SpeedY#
	Field TurnSpeed#
	Field TurnDrag#
	Field TurnAcceleration#
	Field MoveDrag#
	Field MoveAcceleration#
	Field MoveDeceleration#
End Type

Global ME.player = PLAYERcreate()

;main program
While Not KeyDown(1)

	PLAYERmove( ME )
	RenderWorld()
	
	Flip

Wend

;===============================================
;===============================================
;===============================================

Function PLAYERcreate.Player()

	p.player = New Player
	p\SpeedX# = 0
	p\SpeedY# = 0
	p\TurnSpeed# = 0
	p\TurnAcceleration# = 0.03
	p\TurnDrag# = .99
	p\MoveAcceleration# = 0.05
	p\MoveDeceleration# = 0.05
	p\MoveDrag = .99
		
	;MaxSpeed = .03 / ( 1.0 -.99 ) = 3
	;MaxTurnSpeed = .05 / ( 1.0 - .99 ) = 5
		
	p\Model = CreateCone()
	ScaleEntity p\Model, 10, 10,10
	
	Return p
	
End Function

;===============================================
;===============================================
;===============================================

Function PLAYERmove( p.Player )

	;turning
	Turn# = KeyDown (LeftKey) - KeyDown(RightKey)
	p\TurnSpeed# = p\TurnSpeed#  *p\TurnDrag + Turn * p\TurnAcceleration 
	TurnEntity p\Model , 0,0, p\TurnSpeed

	;moving
	Direction# = KeyDown(UpKey) - KeyDown(DownKey)
	TFormNormal 0,1,0,  p\Model, 0
	Thrust# = ( Direction = 1 ) * p\MoveAcceleration - ( Direction = -1 ) * p\MoveDeceleration 
	p\SpeedX = p\SpeedX * p\MoveDrag + Thrust * TFormedX() 
	p\SpeedY = p\SpeedY * p\MoveDrag + Thrust * TFormedY()
	TranslateEntity p\Model, p\SpeedX , p\SpeedY , 0

End Function



Boiled Sweets(Posted 2006) [#6]
Stevie G,

awesome work! MANY THANKS!!!


Morbius(Posted 2006) [#7]
A very nice implementation. How could you add pitch, and or roll contol? And how would you parent a camera to the cone for a cockpit view? Sorry for the simple question, but your sample is much appreciated.


Boiled Sweets(Posted 2006) [#8]
I have managed to add pitch and roll and parent the camera...

But no copying my game, I'm obviously writing a 3d asteroids so don't particularly want every one on the boards from bringing out their own version at the same time!

Function PLAYERmove( p.Player )

	;turning
	TurnX# = KeyDown (LeftKey) - KeyDown(RightKey)
	p\TurnSpeedX# = p\TurnSpeedX#  *p\TurnDrag + TurnX * p\TurnAcceleration 

	TurnY# = KeyDown (DownKey) - KeyDown(UpKey)
	p\TurnSpeedY# = p\TurnSpeedY#  *p\TurnDrag + TurnY * p\TurnAcceleration 

	TurnEntity p\Model , p\TurnSpeedY,0, p\TurnSpeedX

	;moving
	Direction# = KeyDown(Forward) - KeyDown(Back)
	TFormNormal 0,0,1,  p\Model, 0
	Thrust# = ( Direction = 1 ) * p\MoveAcceleration - ( Direction = -1 ) * p\MoveDeceleration 
	p\SpeedX = p\SpeedX * p\MoveDrag + Thrust * TFormedX() 
	p\SpeedY = p\SpeedY * p\MoveDrag + Thrust * TFormedY()
	p\SpeedZ = p\SpeedZ * p\MoveDrag + Thrust * TFormedZ()
	TranslateEntity p\Model, p\SpeedX , p\SpeedY , p\SpeedZ
	TranslateEntity g_bg_nebula_mesh, p\SpeedX , p\SpeedY , p\SpeedZ

End Function


EntityParent camera, ME\Model



Morbius(Posted 2006) [#9]
Thank you! I promise not to copy your game. I'm just trying to understand 3D translation. Good luck.