0 votes

Hello there! :)

So I've fallen in love with the engine - this might be the thing I needed 20 years ago, when tried to make a game, hehe :D.

Anyway - to the point...

I am trying to make a shoot-em-up game. Starting as simple as possible, so I do have a character node rigid body and camera2d as a child node. Drag margins all set to 1 to be able to set offset freely, and rotation enabled.

So I do want the player to be always in the middle horizontally and in the lower half of the screen vertically, always top of the screen facing front of the player.

Everything works fine - the camera follows the player, smoothly (sometimes bit jittery, but nevermind that for now). But when the picture rotates, the offset does not rotate properly - meaning that 90 degrees makes player to appear to the right of the screen, 180 top, 270 left and 0 bottom again. While I want it to be always bottom.

I've tried to work around this by calculating offset based on the rotation using sin/cos duo and it seemed a good idea, but the problem is then with the aspect ratio or something similar - while I've managed to keep the player centered in the bottom half of the screen, it is slightly lower in 90 and 270 degrees meanning that rotation changes the aspect ratio of offsets.

I do hope I've made my problem clear here...

So - how should I approach this problem? Clearly multiplication by the aspect ratio does not solve this problem, as I've tried this - is also off by few percent...

Maybe there is some magic trick to get around this issue?
Ot maybe I should scrap the built in camera and try to write it all by myself? I would really prefer to stay with the built ins as a beginner :)...

Or maybe it is a bug / unexpected behaviour?
I do use the Steam Godot Stable 3.0.6.

Thanks in advance for any advice :)

asked Aug 18, 2018 in Engine by kozaluss (231 points)

1 Answer

0 votes

I'm doing something similar, and had the same problem, if I understnad you correctly.

I think this should work:

var xf = player.gettransform()
camera.set
transform(xf)

basically just make the camera use the players geometry.

If this doesn't work , let me know, I'm actually doing something more complicated with vectors and rotation in order to follow the player, but stay oriented to a gravity center point.

answered Aug 23, 2018 by billyb (66 points)

LoL, same here - I am also rotating player/camera towards center of gravity - what a happy coincidence :D.

I'll try what you suggested. Maybe this would fix the offset problem. And if not - I'll stick to the result I have for now, as it is close enough to be hardly noticeable.

If I had player in center of the screen, problem would not exist. It only appears when using offsets :). And I want area in front of player greater than behind for obvious reasons :)

Now I am also curious about Your project :>.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.