Move camera upwards when key W is pressed (character looks up)

Hello Community,

I’m trying to create a platform game. Player moves Left/Right/Jump. I have an orange box (cam_obj) that follows player and the camera follows this (cam_obj).
image
I’m trying to get my head around Tweening and it’s not sinking in.

The idea is… if player presses W key… then the cam-obj moves up… just above the player_sprite head and if key W is release… return to natural position (player_sprite waist).

I found an article on here for Move camera upwards when character looks up
but there Gdevelop version looked different and it went over my head.

i suspect because my cam_obj is positioned on player… this causes an issue!

Hope this makes sense?
Thanks,
Rob

I would try an object variable tween instead of the position tween. I believe the tween happens before the frame. So, the position action puts the object back to the point values.

You could could use separate move actions and disable the one if a key is pressed but a variable tween would be easier.

You could tween an object variable to the amount of offset and then add or subtract that value from the pointY(…) value.

Here’s an example using the mouse because I’m on my phone.

Edit: you can set the x,y at the same time. This was just an example.

Thanks @Keith_1357,

That does work… Thanks very much.

  • My only issue is now… how do I assign a camera to follow the cam_obj?
    As soon as I add the line (highlighted)… it doesn’t work :frowning:

You got me on that one. I guess you also need to set the camera Y to the cam_obj.Y I’m not sure what you’re ultimately doing.