Locking the camera in Ursina Engine?

Viewed 1634

I am creating a 2d mario style platformer using Ursina Engine, and I want to be able to lock the camera when the player goes left and stop the camera from tracking just the player. I looked through the documentation and it seems pretty barren. Anyone work with this game engine yet?

3 Answers

You can set the camera position and rotation just like with any other Entity. This code will limit x to 0:

camera.x = max(camera.x, 0)

Or if you've parented the camera, you may want to set world position instead:

camera.world_x = max(camera.world_x, 0)

You could use an if statement to clarify what you want and use a previous_x variable.

    prev_x = camera.x

    def update(): #the following code should be added to your update function which is already called...

        if prev_x < camera.x:
        
            lock() 
#this should be a function which is linked
#to your code which moves the camera. 
#A way to do this would be to set a 
#certain variable to true and use the following code:

locked = False
if not locked:
    function_which_moves_camera_left()
    
#The lock() function would be:

def lock():
    locked = True
    
#You could unlock it with the function:

def unlock():
    locked = False

So...

By using an if statement, you can create a function using a variable as a flag. Checking this allows you to lock the camera.

Just add camera.position and camera.rotation:

camera.position=(1, 10, -10)
camera.rotation=(1, 10, -10)
Related