Player Movent and Rotation following an entity

Blitz3D Forums/Blitz3D Programming/Player Movent and Rotation following an entity

Player Movement and Rotation following an entity...

Hiya!

Im trying to come up with a control system that has the players entity move towards and rotate depending on where an entity is moved to around the screen with the mouse. But im having a bit of bother with getting it to work right. And wonder if you great folks, could help me in getting it working. that would be brillo. :)

Here's the code:
;
; Mouse And Entity Movement Test.
; Clyde Radcliffe August 2005.
;

;
; Setup screen.
;
Const XRES=640
Const YRES=480

Graphics3D XRES,YRES
SetBuffer BackBuffer()

;
; Meet the Globals.
;
Global MainCam


Global PlayerSprite

Global MousePointer


;
; Type definitions. Look at that!
;
Type Player
	
	Field GFX
	
	Field X#, Y#, Z#
	
End Type



Type Bullet
	
	Field GFX

End Type


;
; Main program running order.

;
InitializePlayer()
RunPlayer()
End



Function InitializePlayer()
	
	;
	; Setup camera.
	;
	MainCam = CreateCamera()
	
	PositionEntity MainCam,0,0,-5
	
	;
	; Hit the lights.
	;
	Light=CreateLight()
	
	;
	; Create GFX for mouse pointer.
	; used for rotating and positioning the player.
	;
	MousePointer = CreateQuad()
	ScaleEntity MousePointer,.2,.2,.1
	EntityColor	MousePointer,164,000,164
	EntityOrder	MousePointer,1
	
	;
	; Setup player.
	;	
	PlayerSprite = CreateQuad()

	HideEntity 	PlayerSprite
	ScaleEntity PlayerSprite,.25,.25,.25
	

	Add.Player 	= New Player

	Add\GFX		= CopyEntity ( PlayerSprite )
	
	EntityColor	Add\GFX, 000, 000, 255
	
	
End Function



Function RunPlayer()

	While Not KeyHit( 1 )
	
		UpdatePlayer()
		UpdateFire	()
		
		RenderWorld()	
		Flip

	Wend

End Function



Function UpdatePlayer()
	
	;
	; Get mouse position / movement info.
	;
	TranslateEntity MousePointer, Float (MouseXSpeed())/100, -Float (MouseYSpeed())/100, 0
	
	;
	; Center the mouse.
	;
	MoveMouse XRES/2, YRES/2
	
		
	;
	; Update the player.
	;	
	For Update.Player = Each Player
		

		MoveEntity  Update\GFX,.01,.01,0
		
		Rotate( Update\GFX, MousePointer )
		
		;PosX# = MoveToX( Update\GFX, MousePointer )
		;PosY# = MoveToY( Update\GFX, MousePointer )
		
		;Update\X = PosX#
		;Update\Y = PosY#
		
		;PositionEntity Update\GFX, Update\X, Update\Y, Update\Z
		
		;
		; Check for fire.
		;
		If MouseDown( 1 ) Then 
			Fire(Update)
		End If

	Next
	
	
End Function



Function Fire(Update.Player)

	Add.Bullet = New Bullet
	
	Add\GFX = CreateSprite()
	
	ScaleSprite	Add\GFX,.1,.1
	EntityColor	Add\GFX,164,000,00
	
	;
	; Start the bullet at the player
	;
	PositionEntity Add\GFX,EntityX(Update\GFX),EntityY(Update\GFX),EntityZ(Update\GFX)
	
	;
	; Set the bullet's direction for moving
	;
	PointEntity Add\GFX,MousePointer

End Function



Function UpdateFire()
	
	For Update.Bullet = Each Bullet
		MoveEntity Update\GFX,0,0,.4
		
		If EntityInView(Update\GFX,maincam)=False Then
			FreeEntity 	Update\GFX
			Delete		Update
		End If
		
	Next

End Function



Function CreateQuad( Parent=0 )

	QuadMesh	= CreateMesh	(  Parent  )
	surfer		= CreateSurface ( QuadMesh )
	
	;
	; Make Quad - 2 faced.
	;
	AddVertex 	surfer, -1, 1, 0, 0, 0
	AddVertex 	surfer, 1,  1, 0, 1, 0
	AddVertex 	surfer, -1,-1, 0, 0, 1
	AddVertex 	surfer, 1, -1, 0, 1, 1
	
	;
	; front.
	;
	AddTriangle surfer, 0, 1, 2
	AddTriangle surfer, 3, 2, 1
	
	;
	; back.
	;
	AddTriangle surfer,2,1,0
	AddTriangle surfer,1,2,3
	
	UpdateNormals 	QuadMesh
	Return			QuadMesh

End Function



Function Rotate( Target, Destination )

	PosX1# = EntityX( Target )
	PosY1# = EntityY( Target )
	
	PosX2# = EntityX( Destination )
	PosY2# = EntityY( Destination )

	Degrees# = 90 + ATan2( PosY1-PosY2, PosX1-PosX2 ) 
		

	If Degrees < 0 Then
		Degrees = Degrees + 360
	Else If Degrees > 360 Then
		Degrees = Degrees - 360
	End If
	
	RotateEntity Target, 0, 0, Degrees

End Function



Function MoveToX#( Target, Destination )
	
	PosX1# = EntityX( Target )
	
	PosX2# = EntityX( Destination )
	
	If PosX1 < PosX2 Then PositionX#=PositionX# + .1
	If PosX1 > PosX2 Then PositionX#=PositionX# - .1
	
	Return PositionX#

End Function



Function MoveToY#( Target, Destination )
	
	PosY1# = EntityY( Target )
	
	PosY2# = EntityY( Destination )
	
	If PosY1 < PosY2 Then PositionY#=PositionY# + .1
	If PosY1 > PosY2 Then PositionY#=PositionY# - .1
	
	Return PositionY#

End Function


Im after a control system along the lines of Plobb! I first tried this with sprites, and have opted for quad meshes as I was having problems with the entities alpha. Hopefully it'll work with both. And i havent figured out how to have the mouse pointer gfx doesnt effet the player.

What you'll notice is that from the code above, the rotating and movement isnt quite right. There maybe a better method. And if you could help me out, much appreciated.

Many many thanks,
Clyde :)

Hey, try this code out. It makes a pivot point at the desination mesh and move towards it, smoothly. Then, it makes the cube point to the pivot and move towards that smoothly. The result is it will follow and turn towards the sphere. Arrow keys to move. Sorry i'm in a rush, so no time for coments :S

Graphics3D 800,600
SetBuffer BackBuffer()

cam = CreateCamera()
PositionEntity cam,0,0,-30

des = CreateSphere()

start = CreateCube()

pivot = CreatePivot()


While Not KeyHit(1)


	If KeyDown(200) Then MoveEntity des,0,0.1,0
	If KeyDown(208) Then MoveEntity des,0,-0.1,0
	If KeyDown(205) Then MoveEntity des,0.1,0,0
	If KeyDown(203) Then MoveEntity des,-0.1,0,0


	PointEntity pivot,des
	MoveEntity pivot,0,0,EntityDistance#(pivot,des)/50.0

	PointEntity start, pivot
	MoveEntity start,0,0,EntityDistance#(start,pivot)/50.0
	
	UpdateWorld
	RenderWorld
	Flip
Wend


Clyde

a simple solution may be to use the Supercam code from the archives, it will allow you to set an entity to follow another entity, with rotation and distance etc.

It is a fab bit of code and will probably do you well for your task, here it is for you :

http://www.blitzbasic.co.nz/codearcs/codearcs.php?code=798

Simply swap out the camera for the player and the other entity becomes the player.



IPete2.

Wicked! :)

Cool and cheers dudes.I'll check them both out. Im a liitle lost with the supercam method though.

Ross C, I get flickering on the objects when their both together. Is this to do with needing entity order?

I see that it works on the Z positions.

Will the firing work with the similar method too?

Probably z order, because the two meshes are exactly the same Z co-ord. It won't really happen with sprites i don't think. If it does, move them a very small amount on the Z axis.

How do you mean, the firing? Will the bullets home in?

Thanks Ross C. :)

Yeah, will they fire towards the direction of the pivot / mousepointer?

So, even it the mousepointer moves, it will follow you mean?

Clyde,

Let me help! With supercam you would do something like this:

Your programme so far plus...

SuperCam(player_entity, entity_player_has_to_follow, speed to follow #,distance to stay behind #,height above the entity you are following #,0,0)

updateworld
renderworld
etc.

plus at the end of your code so far put the supercam function, you shouldnt have to alter anything in it at all as the variables are passed by the function call. I have given them names you should be able to understand what is needed, but you do not need to know what it does, just that it works, trust me. Place this code at the end of your current programme, just like this...


Function SuperCam(cam,ent,cspeed#,dist#,hite#,xrot#,tilt#)

TFormPoint 0,hite#,-dist#,ent,0

cx#=(TFormedX()-EntityX(cam))*cspeed#
cy#=(TFormedY()-EntityY(cam))*cspeed#
cz#=(TFormedZ()-EntityZ(cam))*cspeed#

TranslateEntity cam,cx,cy,cz
PointEntity cam,ent
RotateEntity cam,xrot#,EntityYaw(cam),tilt#

End Function

Ross C - I've added mouse movement. Not sure on how to position the entities differently so no flickering. Also How about the rotating?


Const XRES=640
Const YRES=480

Graphics3D XRES,YRES
SetBuffer BackBuffer()

Global MainCam 

Global MousePointer 	
Global Player 			

Global control 		
Global controlsprite	

Global ShowMe


InitializeTest()
RunTest()
End



Function InitializeTest()
	
	;
	; Setup camera.
	;
	MainCam = CreateCamera()
	
	PositionEntity MainCam,0,0,-30
	
	;
	; Setup Mouse pointer.
	;
	MousePointer 	= CreateSprite();Sphere()
	
	control 		= CreatePivot()
	controlsprite	= CreateSprite( control )

	ShowMe			= False
	
	;
	; Setup player.
	;
	Player 			= CreateSprite();Cube()

End Function



Function RunTest()

	While Not KeyHit(1)

		UpdatePlayer()
	
		RenderWorld()
		Flip
	
	Wend

End Function



Function UpdatePlayer()
	
	;
	; Get Mouse position info.
	;
	TranslateEntity MousePointer, Float (MouseXSpeed())/10, -Float (MouseYSpeed())/10, 0

	MoveMouse XRES/2, YRES/2
	
	;
	; Point the control "pivot" at the mouse and move.
	;
	PointEntity Control,MousePointer
	MoveEntity 	Control,0,0,EntityDistance#(Control,MousePointer)/50.0
	
	;
	; Point the player at the control pivot and move.
	;
	PointEntity Player, Control
	MoveEntity 	Player,0,0,EntityDistance#(Player,Control)/50.0
	
	;
	; Now you see me now you dont.
	;
	If KeyHit(15) ShowMe=Not ShowMe
	
	If ShowMe
		ShowEntity ControlSprite
	Else
		HideEntity ControlSprite
	End If
	
End Function



IPete2 - Cheers for that. I'll give that a try out.

Many thanks,
Clyde :)

Here's the supercam implementation, but there's still the exact same problem with the rotating. Have you played plobb? As thats what im trying to get towards.

; SuperCam!
;
; by PsychicParrot 2003
;
; 
; Usage : SuperCam(cam,ent,cspeed#,dist#,hite#,xrot#,tilt#)
; 
;

Const XRES=640
Const YRES=480


Graphics3D XRES,YRES;,16,3
SetBuffer=BackBuffer()

Global MainCam
Global campivot


Global Mousepointer
Global Player	


InitializeTest()
RunTest()
End


Function InitializeTest()

	;
	; Create pivot for the camera.
	;
	campivot=CreateCube() 		
	
	HideEntity campivot

	;
	; Setup camera.
	;
	MainCam=CreateCamera()  		

	PositionEntity MainCam,0,0,-30
	
	
	;
	; Add some light.
	;
	light	=CreateLight()


	;
	; Setup mousepointer.
	;
	Mousepointer=CreateCube()
	
	;
	; Setup player.
	;
	Player		=LoadSprite("media\Player1.png");CreateSphere()    


End Function




Function RunTest()

	While Not KeyHit(1)
		
		UpdatePlayer()	
		

		RenderWorld
		Flip

	Wend

End Function



Function UpdatePlayer()

	;
	; Get mouse position / movement info.
	;
	TranslateEntity MousePointer, Float (MouseXSpeed())/100, -Float (MouseYSpeed())/100, 0
	
	;
	; Center the mouse.
	;
	MoveMouse XRES/2, YRES/2
	
	
	If KeyDown(200) Then 
		MoveEntity player,0,0,.2
	End If

	If KeyDown(203) TurnEntity player,0,1,0
	If KeyDown(205) TurnEntity player,0,-1,0

	SuperCam( Player, MousePointer,.02, 0, 0, 0, 0 )

End Function



Function SuperCam( cam, ent, cspeed#, dist#, hite#, xrot#, tilt# )

	TFormPoint 0,hite#,-dist#,ent,0

	cx#=(TFormedX()-EntityX(cam))*cspeed#
	cy#=(TFormedY()-EntityY(cam))*cspeed#
	cz#=(TFormedZ()-EntityZ(cam))*cspeed#

	TranslateEntity cam, cx, cy, cz
	PointEntity 	cam, ent
	RotateEntity 	cam, xrot#, EntityYaw(cam), tilt#

End Function


Cheers and thankyou so much,
Clyde :)

What every happened to good old-fashioned trig?

I realize Plobb was likely done in 3d, but I made this as simple (and quickly) as possible to show how to code a Plobb-style movement scheme. It should be trivial to call PositionEntity() and RotateEntity() instead of drawing geometric shapes to the backbuffer.

Other than the edge-wrapping occurring farther outside the screen boundaries in the real Plobb, I don't believe I've forgotten anything.

If anyone has a better way to get an angle from dx/dy than what I'm doing, please let me know. I feel dirty using that many IF tests for something so simple.

Graphics 640, 480
SetBuffer BackBuffer()
;HidePointer

Const player_max_turn# = 3.0
Const weapon_cooldown = 15
Const bullet_speed# = 3.0

Type bullet
	Field x#, y#, vx#, vy#
End Type

Type player
	Field x#, y#, dir#, weapon_heat
End Type

Global p.player = New player
p\x = GraphicsWidth()/2
p\y = GraphicsHeight()/2

While Not KeyHit(1)
	; determine angle from player to mouse
	Local dir#
	Local dx# = p\x - MouseX()
	Local dy# = p\y - MouseY()
	If dy < 0 Then dir = ATan(dx/dy)
	If dy > 0 Then dir = ATan(dx/dy) + 180
	If dy = 0 Then ; don't divide by 0!
		If dx < 0 Then dir = 90 Else dir = 270
	EndIf
	
	; turn player toward mouse
	Local dang# = (dir - p\dir + 360+360) Mod 360
	If dang >= 180 Then p\dir = p\dir - min(player_max_turn, Abs(dang))
	If dang < 180 Then p\dir = p\dir + min(player_max_turn, Abs(dang))
	p\dir = (p\dir + 360) Mod 360 ; don't let p\dir out of 0-360 range
	
	; determine distance from player to mouse
	Local dist# = Sqr(dx*dx + dy*dy)

	; move player forward
	Local speed#
	If dist < 25 Then
		speed = 0
	Else
		speed = (min(dist, 100)) / 100
	EndIf
	p\x = p\x + Sin(p\dir) * speed
	p\y = p\y + Cos(p\dir) * speed
	
	; wrap player if he goes off the edge of the screen
	p\x = (p\x + GraphicsWidth()) Mod GraphicsWidth()
	p\y = (p\y + GraphicsHeight()) Mod GraphicsHeight()

	; fire weapon
	p\weapon_heat = p\weapon_heat - 1
	If MouseDown(1) And p\weapon_heat <= 0 Then
		p\weapon_heat = weapon_cooldown
		b.bullet = New bullet
		b\x = p\x
		b\y = p\y
		b\vx = Sin(p\dir) * bullet_speed
		b\vy = Cos(p\dir) * bullet_speed
	EndIf
	
	; update bullets
	For b.bullet = Each bullet
		b\x = b\x + b\vx
		b\y = b\y + b\vy
		; remove bullets that have disappeared off the screen
		If b\x < 0 Or b\y < 0 Or b\x>GraphicsWidth() Or b\y>GraphicsHeight() Then Delete b
	Next

	; i thought i told you good graphics!
	Cls
	; draw player
	Oval(p\x-6, p\y-6, 12, 12, True)
	Line(p\x, p\y, p\x+Sin(p\dir)*10, p\y+Cos(p\dir)*10)
	; draw bullets
	If MouseDown(2) Then Stop
	For b.bullet = Each bullet
		Oval(b\x-2, b\y-2, 4, 4, True)
	Next
	; draw mouse reticle
	Oval(MouseX()-10, MouseY()-10, 20, 20, False)
	; you heard me!
	Flip
Wend

Function min#(a#, b#)
	If a < b Then Return a Else Return b
End Function


Thanks Octothorpe dude: - Thats great, if I were doing a 2D game. Will that method work and convert to be used with entites in a Blitz 3D environment?

Ross C and IPete2 - any luck with the rotating / firing part with the codes above, please dudes?

I have 3 and a half methods ( including mine, hehehe ) would be great now, if we can get them or at least one of them polished! :P

Cheers and many thanks once again for your great and much appreciated help.
-Clyde :)

Thats great, if I were doing a 2D game. Will that method work and convert to be used with entites in a Blitz 3D environment?


Yes. Sorry, I thought I made that clear above. The principles are the same - you're essentially making a 2d game, so the math and movement code don't have differ, just the display code.

Set up your entities, camera, and lights as you were doing earlier, then simply call PositionEntity(e,x,y,0) and RotateEntity(e,0,0,dir) to move your entities to the spots you've calculated for them instead of drawing ovals at those spots. Oh, and replace my sloppy use of 0 and GraphicsHeight() and GraphicsWidth() with variables for your map bounds.

Im making a right pigs ear of things. Please could you show me the code working with B3D commands.

Cheers,
Clyde

I don't feel like doing it for you, but I wouldn't mind helping you to understand how to do it yourself. What exactly are you having trouble with?

Thanks. Im going to go for a simple cursor key movement, as this is begining to annoy me now.

Yes. Sorry, I thought I made that clear above. The principles are the same - you're essentially making a 2d game, so the math and movement code don't have differ, just the display code.

Set up your entities, camera, and lights as you were doing earlier, then simply call PositionEntity(e,x,y,0) and RotateEntity(e,0,0,dir) to move your entities to the spots you've calculated for them instead of drawing ovals at those spots. Oh, and replace my sloppy use of 0 and GraphicsHeight() and GraphicsWidth() with variables for your map bounds.


That mate. As there'll be more then simply just putting in positionentity and rotatesprite or rotatentity.

Clyde, you need to set you sprite view mode differently.

Your Function should now look like:

Function InitializeTest()
	
	;
	; Setup camera.
	;
	MainCam = CreateCamera()
	
	PositionEntity MainCam,0,0,-30
	
	;
	; Setup Mouse pointer.
	;
	MousePointer 	= CreateSprite();Sphere()
	
	control 		= CreatePivot()
	controlsprite	= CreateSprite( control )

	ShowMe			= False
	
	;
	; Setup player.
	;
	Player 			= CreateSprite();Cube()
	SpriteViewMode Player,3

End Function


:o)

As for the flickering, just move one of the sprites slightly in the Z direction a very small amount.

Cool and thanks mate. And how would the player rotating fit in?

Hmm, you could grab the (x,y) co-ords of the mouse move, before you reset it's position to the middle of the screen. Then, work out the angle between the centre of the screen and the co-ords, and rotate the player to that. It might be a little jerky tho. I'm not entirely sure about that tbh...

Thanks there Ross C :)

I'll have ago at this later ron. I did have ago in my intitial post.

And how would the player rotating fit in?


You've failed to explain what you want. The only reason I know what you're talking about is because I've played Plobb a lot.

As there'll be more then simply just putting in positionentity and rotatesprite or rotatentity.


Yes, you'll also need to set up your entities, camera, and lights as you were doing earlier (as I already mentioned above.) This is all that's required; create your entities, then in each update, calculate where they should move to and position them.

Have a look at how little I changed below. I simply moved my code into your Update*() functions. I also had to move the camera back to account for the larger scale of x,y coords in my code.

;
; Mouse And Entity Movement Test.
; Clyde Radcliffe August 2005.
;

;
; Setup screen.
;
Const XRES=640
Const YRES=480

Graphics3D XRES,YRES
SetBuffer BackBuffer()

;
; Meet the Globals.
;
Global MainCam

Global MousePointer

Const player_max_turn# = 3.0
Const weapon_cooldown = 15
Const bullet_speed# = 3.0

Type bullet
	Field x#, y#, vx#, vy#, entity
End Type

Type player
	Field x#, y#, dir#, weapon_heat, entity
End Type

Global p.player = New player
p\x = GraphicsWidth()/2
p\y = GraphicsHeight()/2


;
; Type definitions. Look at that!
;


;
; Main program running order.

;
InitializePlayer()
RunPlayer()
End

Function initializeplayer()
	;
	; Setup camera.
	;
	MainCam = CreateCamera()
	
	positionentity MainCam, graphicswidth()/2, -graphicsheight()/2, -graphicswidth()/2
	
	;
	; Hit the lights.
	;
	Light=CreateLight()
	
	;
	; Create GFX for mouse pointer.
	; used for rotating and positioning the player.
	;
	MousePointer = CreateQuad()
	ScaleEntity MousePointer,10,10,1
	EntityColor	MousePointer,164,000,164
	EntityOrder	MousePointer,1
	
	;
	; Setup player.
	;	
	p\entity = CreateQuad()

	ScaleEntity p\entity,12,12,12
	EntityColor	p\entity, 000, 000, 255
End Function

Function RunPlayer()

	While Not KeyHit( 1 )
	
		UpdatePlayer()
		UpdateFire	()
		
		RenderWorld()	
		Text 0,0,"This is a hack job, polish it yourself"
		Flip

	Wend

End Function

Function UpdatePlayer()
	; determine angle from player to mouse
	Local dir#
	Local dx# = p\x - MouseX()
	Local dy# = p\y - MouseY()
	If dy < 0 Then dir = ATan(dx/dy)
	If dy > 0 Then dir = ATan(dx/dy) + 180
	If dy = 0 Then ; don't divide by 0!
		If dx < 0 Then dir = 90 Else dir = 270
	EndIf
	
	; turn player toward mouse
	Local dang# = (dir - p\dir + 360+360) Mod 360
	If dang >= 180 Then p\dir = p\dir - min(player_max_turn, Abs(dang))
	If dang < 180 Then p\dir = p\dir + min(player_max_turn, Abs(dang))
	p\dir = (p\dir + 360) Mod 360 ; don't let p\dir out of 0-360 range
	
	; determine distance from player to mouse
	Local dist# = Sqr(dx*dx + dy*dy)

	; move player forward
	Local speed#
	If dist < 25 Then
		speed = 0
	Else
		speed = (min(dist, 100)) / 100
	EndIf
	p\x = p\x + Sin(p\dir) * speed
	p\y = p\y + Cos(p\dir) * speed
	
	; wrap player if he goes off the edge of the screen
	p\x = (p\x + GraphicsWidth()) Mod GraphicsWidth()
	p\y = (p\y + GraphicsHeight()) Mod GraphicsHeight()

	; fire weapon
	p\weapon_heat = p\weapon_heat - 1
	If MouseDown(1) And p\weapon_heat <= 0 Then
		p\weapon_heat = weapon_cooldown
		b.bullet = New bullet
		b\x = p\x
		b\y = p\y
		b\vx = Sin(p\dir) * bullet_speed
		b\vy = Cos(p\dir) * bullet_speed
	
		b\entity = CreateQuad()

		ScaleEntity b\entity,6,6,6
	
		EntityColor	b\entity,164,000,00
	EndIf
	
	; update entities
	PositionEntity p\entity, p\x, -p\y, 0
	RotateEntity p\entity, 0, 0, p\dir
	PositionEntity MousePointer, MouseX(), -MouseY(), 0
End Function

Function UpdateFire	()
	
	; update bullets
	For b.bullet = Each bullet
		b\x = b\x + b\vx
		b\y = b\y + b\vy
		; update entities
		PositionEntity b\entity, b\x, -b\y, 0
		; remove bullets that have disappeared off the screen
		If b\x < 0 Or b\y < 0 Or b\x>GraphicsWidth() Or b\y>GraphicsHeight() Then
			FreeEntity b\entity
			Delete b
		EndIf
	Next
End Function

Function CreateQuad( Parent=0 )

	QuadMesh	= CreateMesh	(  Parent  )
	surfer		= CreateSurface ( QuadMesh )
	
	;
	; Make Quad - 2 faced.
	;
	AddVertex 	surfer, -1, 1, 0, 0, 0
	AddVertex 	surfer, 1,  1, 0, 1, 0
	AddVertex 	surfer, -1,-1, 0, 0, 1
	AddVertex 	surfer, 1, -1, 0, 1, 1
	
	;
	; front.
	;
	AddTriangle surfer, 0, 1, 2
	AddTriangle surfer, 3, 2, 1
	
	;
	; back.
	;
	AddTriangle surfer,2,1,0
	AddTriangle surfer,1,2,3
	
	UpdateNormals 	QuadMesh
	Return			QuadMesh

End Function

Function min#(a#, b#)
	If a < b Then Return a Else Return b
End Function


Firstly, can I say a whooping big thanks to you dudes for helping me out and along with this. It's brilliant.

OctoThorpe - Just I had problems before with using mousex() / mousey() with entities. I used the translateentity and movemouse XRES/2,YRES/2.

And was ( and still am to be honest ) a little puzzled with the Camera setup. As im now trying to put in appropraiate boundary checks. Not quite sure if im going to opt for screen wrapping or with in the confines of the screen.

Cheers,
Clyde

A ha! I finally figured it out! The solution ended up being a lot simpler than the 6 lines of code I've got accomplishing the same thing in my GUI prototype!
positionentity MainCam, graphicswidth()/2, -graphicsheight()/2, -graphicswidth()/2
I've fixed my code above.

And was ( and still am to be honest ) a little puzzled with the Camera setup.


The camera set up and playfield area are both arbitrary, all that's important is that the camera shows the entire playfield. I chose to make the playfield stretch from (0,0,0) to (0,graphicwidth(),graphicsheight()), so I needed to move the camera back far enough to show it.

Just I had problems before with using mousex() / mousey() with entities. I used the translateentity and movemouse XRES/2,YRES/2.


Huh? Don't you have to use MouseX() and MouseY() to do your TranslateEntity() on your mouse-representing entity?

If you're having trouble with 3d stuff, I highly recommend you play around in 2d until you understand how everything works. There's a lot less to grasp for a beginning programmer in the land of two dimensions. Also, you might get help that's more to your taste if you post to the Blitz3D Beginners Area.


Don't you have to use MouseX() and MouseY() to do your TranslateEntity() on your mouse-representing entity?


Nope as I was advised to use MouseXSpeed() and MouseYSpeed()

I've been using 2D for many years. You threw me when presenting the option of a 2D math routine within Blitz 3D. Moving entities based on the mouse in 3D is an area i've not done a busting amount on, and theres not a great deal on offer in the commands reference - hence my asking for help on it. Of which I thank you all once again.

Cheers and all the best,
Clyde

My bad, I wasn't aware there were such commands! :)

Either approach will work. If you wanted to use your translateentity and movemouse approach, you would need to get the mouse (entity's) x and y coords via EntityX() and EntityY() when you need them for any calculations. You'd also need bounds-checking on the mouse entity to prevent the player from rolling it off the "screen".

Thanks mate, I'll give this a whirl over the weekend.