Camera Should Not Go Back When Left Key is Pressed

Hello there.

I am using the camera lerp function to make the camera follow the object, most probably this:

lerp(CameraX(),Object.X(),0.05)

Applying this, the camera is following the x position of the object, or in simple words, it is following the object. That’s cool.

However, I have a problem. If I press the left button or the back button during the preview, the object will indeed go back toward the left side of the screen. My problem is that the camera is also going backward. I am new to this, so I don’t know any advanced stuff, just a beginner.

I don’t want to make the camera go backward as well. It should only follow the object when the object is moving forward or the right key is pressed. But if the left key is pressed, only the object or the player should go backward, not the camera. The camera should stop moving immediately there when the left key is pressed and only continue moving when the forward or right key is pressed. Also, the player should not be able to go beyond the left border of the camera. I hope you are understanding what I’m trying to say.

How can I make this possible in Gdevelop? Thanks in advance :slight_smile:

Update: I figured out that part when the player is moving forward, then only the camera should move. All I had to do was add a condition in front of the lerp function that:

object has the right key pressed or simulated

But I could not figure out the second part where the object is going beyond the left boundary of the camera. It should stop going beyond the left boundary of the camera. I still need help on this. How can I achieve this?

I’m not sure if this is quite what you need, but I stop the camera moving when it gets to the far left and far right of my level using this action:
image
This stops the player seeing outside of the level, since it stops scrolling when you get to the edges.

Hello there. Thanks for your response.

No! That is not what I want. I have already applied the enforce camera feature and it will stop moving the camera beyond the position you have set. This is basically used at the stage’s end, copying the scene’s x and y positions. No, that is not what I want. As I have written in the update above, I have already found a solution for stopping camera movement at specific points. That is not my problem.

My problem is the second part. Suppose the object moves from Point A to B. The object will reach point B and so will the camera. I have found a solution to that. But when the object will reach point B, it should not be able to return back to point A. Consider this, point B is the left border of the camera. How can I achieve that?

Sorry. I’m a beginner myself. Maybe someone else can help.