r/PakGameDev • • Jun 04 '25

help need help with camera tracking

i am making a runner game and ive made main camera follow sphere(players) motion but when the ball drops onto the plaform the camera is going below the platform however ive already set the camera distance which tells at how much distance the camera will be from the player.but the camera keeps falling down please help needed

7 Upvotes

11 comments sorted by

1

u/Adeeltariq0 Indie on Itch Jun 05 '25

Your distance field is subtracting 2 from the ball position's Y. So it'll always be below it. Add 2 instead or set it to -2 in the inspector.

1

u/Sallew21 Jun 05 '25

As stated above, if u subtract camera's position in update() function, it is done every single frame, so for example if u subtracted 2 from the y position in the update() function, and assuming ur running at 60 fps, it will subtract 120 (2*60 = 120) from the y position every second.

What u can do is just set the y position of the camera to -2 in the inspector.

2

u/Adeeltariq0 Indie on Itch Jun 05 '25

Doing the subtraction in the update function is not the problem because he is setting it relative to the ball position. It won't subtract 120. It'll just set the position to ballposition - 2.

1

u/Sallew21 Jun 05 '25

Aah ur right, i missed that. Thanks for correcting me :D

1

u/Timely-Today-8154 Indie on Steam Jun 05 '25

The ball’s positionY on platform is 1.67 and distanceY is 2. When you say ball.position - distance, it means 1.67-2=-0.33 which will always below to the ball

1

u/[deleted] Jun 04 '25

[removed] — view removed comment

1

u/Ahmad1765 Jun 05 '25

but then the camera will also rotate with ball

1

u/[deleted] Jun 05 '25

[removed] — view removed comment

2

u/Ahmad1765 Jun 05 '25

now that might work

good idea