0 votes

I have two players. Camera is attached to player 1. When player 2 goes out of camera view I want to print("out of bounds"). It's a 2D game with camera2d node.

How should I go about doing that?

Godot version 3.4.4
in Engine by (202 points)

Have you tried checking the root Viewport's boundaries against the second player's position? For example:

# Do this check when the second player moves.
if player2.position > get_tree().get_root().size:
    print("Player 2 is out of bounds.")

I don't know whether this will work, but it's a start.

Thank you! But what if camera is zoomed out. I guess I will have to do some adjustments.

1 Answer

+1 vote
Best answer

Hi, you might find this tutorial from Kids Can Code helpful: Entering/exiting the screen.

Specifically the part about VisibilityNotifier2D.

Good luck!

by (141 points)
selected by

Thank you! I will try this.

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.