Can anyone notice the problem with this code?

Blitz3D Forums/Blitz3D Programming/Can anyone notice the problem with this code?

Ash_UK(Posted 2005) [#1]
Please, could anyone tell me whats wrong with this code, basically when i run it, my player model is miles away from where it should be. I am using 3DS Max to do the models if thats any help at all :)
I think it's deffinitely something to do with the code before the main loop but i don't know what the problem is.

Here is my code:

Graphics3D 800,600
SetBuffer BackBuffer()


;COLLISION VARIABLES
;///////////////////////
Const TRACK_COL = 1		;track collision type
Const CAR_COL = 2		;car collision type
;///////////////////////


;LOAD 3D OBJECTS
;/////////////////////////////
Global cam_piv = CreatePivot()
Global cam = CreateCamera()
	CameraRange cam,1,10000
Global light = CreateLight()
;/////////////////////////////

;///////////////////////////////////////////////
Global player = LoadMesh("models/ship.3ds")		;player craft model
Global track_model = LoadAnimMesh("models/track.3ds")		;track model
	Global pos = FindChild(track_model,"pos")		;find position point in track
	Global dir = FindChild(track_model,"dir")		;and direction point
	Global track = FindChild(track_model,"track") 	;extract main track from model
;////////////////////////////////////////////////


;POSITION OBJECTS
;///////////////////////////////////////////////////////////////
PositionEntity player,EntityX(pos),EntityY(pos),EntityZ(pos)	;position the player then face 
PointEntity player,dir 											;them in the right direction
;///////////////////////////////////////////////////////////////

;///////////////////////////////////////////////////////////////
EntityParent cam_piv,player	
PositionEntity cam_piv,0,5,-10				
PointEntity cam,cam_piv
;///////////////////////////////////////////////////////////////














;**************
;MAIN GAME LOOP
;**************
;//////////////////
While Not KeyHit(1)
	
	player_control
	update_cam
		
	UpdateWorld
	RenderWorld
	
	Flip

Wend
End
;//////////////////














;*********
;FUNCTIONS
;*********



;PLAYER CONTROL
;///////////////////////////////
Function player_control()		;function for all player controls

	If KeyDown(200) Then 
		MoveEntity player,0,0,1
	EndIf
	
	If KeyDown(208) Then
		MoveEntity player,0,0,-1
	EndIf
	
	If KeyDown(203) Then
		RotateEntity player,EntityPitch(player),EntityYaw(player)+1,EntityRoll(player)
	EndIf
	
	If KeyDown(205) Then
		RotateEntity player,EntityPitch(player),EntityYaw(player)-1,EntityRoll(player)
	EndIf
	
End Function
;///////////////////////////////


;UPDATE CAM
;///////////////////////////
Function update_cam()		;function for updating the camera movements to track the player

	PointEntity cam,cam_piv
	MoveEntity cam,0,0,EntityDistance(cam,cam_piv)-10
	PointEntity cam,player
	
End Function
;///////////////////////////


And here is an image of my screen in 3DS Max:


The 2 boxes, represet two points - Position and direction (the player is placed at the position point, then turned to face the direction point). As you can see, they are on the track here, but when i run my code the player is not placed where it should be.

Thanks


Stevie G(Posted 2005) [#2]
Maybe use the global params when positionentity.

Stevie


WolRon(Posted 2005) [#3]
I can only assume that the 'position' of the 'pos' entity is not where you think it is, such as, for example, the center of the map.

This is just a guess however.


jfk EO-11110(Posted 2005) [#4]
without to read the source I do a guess: Make sure Collision handlers won't prevent PositionEntity from working. To make this a simple task, do something like

function PositionEntityForced(m,x#,y#,z#,glob)
 hideentity m
 positionentity m,x,y,z,glob
 showEntity m
end function

HideEntity will also flush it's collision state.

EDIT . uh I see you have no cosslision in there, so it must be something diffrent - yes, could be a local/global thing. EntityX defaults the flag to local IIRC.


Ash_UK(Posted 2005) [#5]
Thanks guys for all your help. I have also used the global co-ordinate setting and still no luck. Hmmmm, this is a tough one :(


stayne(Posted 2005) [#6]
try aligning your player model in 3dsmax to the center of the grid? right click your model, click the little box to the right of "Move" and enter in all zeros to move it to the center.


jfk EO-11110(Posted 2005) [#7]
Make sure the pivot of the children is set to the child objects center. When you are using 3dsmax, you need to use "affest pivot only" and "center to object" or somthing.


Ash_UK(Posted 2005) [#8]
Hmmm, cheers guys :) I give this a try!!

Thanks


Ash_UK(Posted 2005) [#9]
Well, i used markd's method and.....IT WORKS!!!!
Thanks a lot man :D
And thankyou so much to everyone who has tried to solve this problem for me :)