turn the child only ?
Blitz3D Forums/Blitz3D Beginners Area/turn the child only ?
| ||
H! I have this code: player = CreatePivot() p_body = CreateCone(20,1,player) p_head = CreateSphere(8,p_body) cam_target = CreatePivot(p_head) camera = CreateCamera(cam_target) If KeyDown(key_arrowpad_left) Then p_yaw#=+p_speed# TurnEntity p_head,p_pitch#,p_yaw#,p_roll# EndIf If KeyDown(key_arrowpad_right) Then p_yaw#=-p_speed# TurnEntity p_head,p_pitch#,p_yaw#,p_roll# EndIf If KeyDown(key_arrowpad_up) Then p_z#=+p_speed# MoveEntity player,p_x#,p_y#,p_z# EndIf If KeyDown(key_arrowpad_down) Then p_z#=-p_speed# MoveEntity player,p_x#,p_y#,p_z# EndIf When turn the p_head (a child of p_body) then the p_body (parent) turn's ? How must I fix this ? I want to have one "player" and want to turn the head for example without the body. Thanks |
| ||
Hmmm...check you key_arrowpad_down variables. It's the only thing i can see, since all the code isn' there :) |
| ||
Const key_arrowpad_up = 200 Const key_arrowpad_left = 203 Const key_arrowpad_right= 205 Const Key_arrowpad_down = 208 But its possible to turn only the child with-out the parent? Full code Graphics3D 1024,768,16,1 SetBuffer BackBuffer() Global player,p_body,p_head Global p_x# = 0 Global p_y# = 1 Global p_z# = 0 Global p_speed# = 1 Global p_pitch# = 0 Global p_yaw# = 0 Global p_roll# = 0 Global camera Global c_x# = 0 Global c_y# = 4 Global c_z# = -10 Global c_speed# = 1 Global c_yaw# = 0 Global type_camera = 3 Global type_level = 2 Global type_player = 1 Const key_arrowpad_up = 200 Const key_arrowpad_left = 203 Const key_arrowpad_right= 205 Const Key_arrowpad_down = 208 ; De speler ;---+ player = CreatePivot() PositionEntity player,p_x#,p_y#,p_z# RotateEntity player,p_pitch#,p_yaw#,p_roll# EntityType player,type_player ScaleEntity player,4,4,4 ;body p_tex = LoadTexture("armour.pcx") p_body = CreateCone(20,1,player) EntityTexture p_body,p_tex ;head p_head = CreateSphere(8,p_body) EntityTexture p_head,p_tex PositionEntity p_head,p_x#,(p_y#+1),p_z# ;De scene ; Ground ground = CreatePlane() ground_tex = LoadTexture("plane.jpg") EntityTexture ground,ground_tex PositionEntity ground,0,0,0 EntityType ground,type_level ; Level level = LoadMesh("level.3ds") PositionEntity level,30,-1,0 EntityType level,type_level ScaleEntity level,2,2,2 ; Create Camera cam_target = CreatePivot(p_head) camera = CreateCamera(cam_target) PositionEntity camera,c_x#,c_y#,c_z# EntityType camera,type_camera ; Handle Collisions Collisions type_player,type_level,2,2 Collisions type_camera,type_level,2,2 ; Light AmbientLight 255,255,255 ;Game Loop ;------------------------------------------------ While Not KeyHit(1) Cls reset_vars() player_move() UpdateWorld RenderWorld player_info() Flip Wend End Function player_info() Text 0,FontHeight()*1,"p_x:"+EntityX(player) Text 0,FontHeight()*2,"p_y:"+EntityY(player) Text 0,FontHeight()*3,"p_z:"+EntityZ(player) Text 0,FontHeight()*4,"p_speed:"+p_speed# Text 0,FontHeight()*5,"p_yaw:"+EntityYaw(player) Text 0,FontHeight()*6,"p_roll:"+EntityRoll(player) Text 0,FontHeight()*7,"p_pitch:"+EntityPitch(player) Text 0,FontHeight()*8,"p_collisions:"+CountCollisions(player) End Function Function reset_vars() p_x# = 0 p_y# = 0 p_z# = 0 p_pitch# = 0 p_yaw# = 0 p_roll# = 0 End Function |
| ||
Um... yer kinda missing the all-important player_move function there. To aid your debugging though, check to ensure that you are only turning the child entity. Turning the child does not affect the parent entity at all, so if parented to the body you should have no problems. Ensure that your heirarchy is correct by running some simple debug tests first. |
| ||
Works ok if you add this back in---(from your first letter) Function player_move() If KeyDown(key_arrowpad_left) Then p_yaw#=+p_speed# TurnEntity p_head,p_pitch#,p_yaw#,p_roll# EndIf If KeyDown(key_arrowpad_right) Then p_yaw#=-p_speed# TurnEntity p_head,p_pitch#,p_yaw#,p_roll# EndIf If KeyDown(key_arrowpad_up) Then p_z#=+p_speed# MoveEntity player,p_x#,p_y#,p_z# EndIf If KeyDown(key_arrowpad_down) Then p_z#=-p_speed# MoveEntity player,p_x#,p_y#,p_z# EndIf End Function |
| ||
You may have your heirarchy set up incorrectly. The whole point of parent-child relationships is that moving an object will also move all of its children but will not affect its parents. |