0
\$\begingroup\$

I'm making a TEST 3d platformer where the camera follows the player from above. Normally I would make the camera move at the same time when the player moved, for example:

If KeyDown(17) Then TranslateEntity player1,0,0,0.1
If KeyDown(17) Then TranslateEntity camera,0,0,0.1

But this doesn't work with my "gravity" code which is just:

If Not Keydown(57) Then TranslateEntity player1,0,0,-0.1

I cannot use the same code with the camera, otherwise, the camera will infinitely go down if the player didn't press space(57)

I want to put player1's coordinates to an entity(?) so that the x and z of the camera would be the same as player1's, but the y coordinates would be y+30

I've tried to do:

x = EntityX(player1)
y = EntityY(player1)
z = EntityZ(player1)

camera = CreateCamera
PositionEntity camera,x,y+30,z

But when I run the program, it shows the Entity does not exist error

Entity does not exist

If it does help, I will post the entire code. The game isn't completed yet as I'm still making it, and I will try to improve it

;-------------------------------------------
Graphics3D 640,480,32,2
SetBuffer BackBuffer()

view = CreateCamera()
CameraClsColor view,5,10,255
PositionEntity view,x,y+30,z
RotateEntity view,75,0,0

x = EntityX(player1)
y = EntityY(player1)
z = EntityZ(player1)

type_map = 1
type_player = 2
type_player2 = 3

light = CreateLight()

player1 = CreateCube()
PositionEntity player1,0,0,10
EntityColor player1,255,75,0 
EntityType player1, type_player

player2 = CreateCube()
PositionEntity player2,-5,0,10
EntityColor player2,10,20,30
EntityType player2, type_player2

map = LoadMesh("drinks.b3d")
PositionEntity map,0,-8,130
ScaleEntity map,4,4,4
EntityType map, type_map



While Not KeyDown(1) 

Collisions type_player, type_map,2,2
Collisions type_player2, type_map,2,2
Collisions type_player, type_player2,2,2
Collisions type_player2, type_player,2,2

If KeyDown(17) TranslateEntity player1,0,0,0.1
If KeyDown(31) TranslateEntity player1,0,0,-0.1
If KeyDown(30) TranslateEntity player1,-0.1,0,0
If KeyDown(32) TranslateEntity player1,0.1,0,0

If KeyDown(17) TranslateEntity view,0,0,0.1
If KeyDown(31) TranslateEntity view,0,0,-0.1
If KeyDown(30) TranslateEntity view,-0.1,0,0
If KeyDown(32) TranslateEntity view,0.1,0,0

If Not KeyDown(57) Then TranslateEntity player1,0,-0.1,0
If KeyDown(57) Then TranslateEntity player1,0,0.1,0
If KeyDown(57) Then TranslateEntity view,0,0.1,0



RenderWorld
UpdateWorld
Flip

Wend

End
;-------------------------------------------
\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

moving camera with player by two if-statements isnt very good solution, use EntityParent() function (EntityParent(view,player1)), so "view"-entity (camera) will always follow it's parent (player) without other code.

also you are trying to get player1 position (x=EntityX(player1)...) BEFORE it got created, so function trying to get position of entity that does not exists.

; fixed example: 
player1=CreateCube()

x=EntityX(player1) ; ...
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .