Advanced Movement

Blitz3D Forums/Blitz3D Beginners Area/Advanced Movement

Let's say I have a cube, I am using 4 numpad keys 8 and 2 to move it on the Z axis. 4 and 6 to move it on the X axis. This is for a block building type game.

I'm in a 3rd person view and I can move around.

When I am facing forward on the Z axis and am moving the cube forward, everything is fine. But if I move to another side of the cube, say, the left side, and turn to look at it while moving it with the numpad buttons, it becomes very confusing which buttons move it which way.

So what I am asking is,how can I use TForming or AlignToVector to make the X and Z movement for the cube relative to which way I'm facing it? I would do it myself but those two commands are confusing to set up.

aligntovector would be worthless and tform sounds like much more than needed as well.

Use the moveentity command and actually rotate your cube. That way the "z axis" will always be forward / backward and x axis always right / left

Well I'm basing what I'm doing off of the game Blockland. The blocks on there don't need to rotate to move relative to which way you are facing. I need a way to move it without messing it up. Are you sure TForming is too much? Or is there another way?

Here's a way I thought of, that works

I used (EntityYaw(model)/29) to determine which way I'm facing in small increments (-6 to 6) and changed the keyhit()'s accordingly.

I think you're looking for movement relative to the camera. Here's an example I posted a while back which should help ..

Graphics3D 640,480,16,1

Global LIGHT = CreateLight()
Global PLANE = CreatePlane() 
EntityColor PLANE, 200,100,100
texture = CreateTexture( 32, 32 )
SetBuffer TextureBuffer( texture )
For y = 0 To 1
	For x = 0 To 1
		Color 100, 150+25*( ( x+y) Mod 2 ) , 100
		Rect x*16,y*16,16,16,1
	Next
Next
SetBuffer BackBuffer()
ScaleTexture texture, 50,50
EntityTexture PLANE, texture
FreeTexture texture

Global CUBE = CreateCube() : FitMesh CUBE, -2,0,-2,4,10,4 
Tmp = CreateCube() : FitMesh Tmp, -1,7,2,2,2,2 : AddMesh Tmp, CUBE : FreeEntity Tmp
Global TARGET = CreatePivot()

Global CAMERApivot = CreatePivot()
Global CAMERA = CreateCamera( CAMERApivot )
PositionEntity CAMERA, 0,50,-50
PointEntity CAMERA , CAMERApivot

While Not KeyDown(1)

	PositionEntity CAMERApivot , EntityX( CUBE ) , 0, EntityZ( CUBE )
	TurnEntity CAMERApivot, 0 , KeyDown(31) - KeyDown(30) , 0
	
	;move relative to camera
	Mx# = KeyDown(205) - KeyDown(203)
	Mz# = KeyDown(200) - KeyDown(208 )

	If Mx <> 0 Or Mz <> 0
		;move relative to camera
		TFormVector Mx, 0, Mz , CAMERApivot , 0
		TranslateEntity CUBE, TFormedX(), 0, TFormedZ()
		;turn relative to movement
		PositionEntity TARGET, EntityX( CUBE ) + TFormedX() , 0, EntityZ( CUBE ) + TFormedZ()
		TurnEntity CUBE, 0 , DeltaYaw( CUBE, TARGET ) * .25, 0
	EndIf
	
	RenderWorld()
	Flip

Wend


:) Something simpler to learn from, thanks.