0 votes

Hi!
I want to get " iscolliding()" from a node above to a CanvasLayer node's script and getnode("").iscolliding() doesnt work...
Im trying to make my player object to add value when its colliding in the CanvasLayer's script, because i get a little bug when i make part of it in Kinematic2D body's script..
How can i call "is
colliding()" from kinematic2d to canvaslayer's script?

in Engine by (225 points)

What is a "node above", what "little bug" means?

Remember that is_colliding only works after move in the same physics frame.

Id have showed you if could have puted screenshot in this forum : /
But i kinda did fix the bug..
And thanks about thetip! :)

3 Answers

0 votes

To call one layer up, use get_parent() instead of get_node().

by (1,302 points)
0 votes

You can access a node's parent with get_parent(), but I advise against it.
You should always try to write your code so that you only access nodes inside the current scene, otherwise you will create scenes that you can only instantiate if the surrounding scene is built the way you expect it to.

In your case it would probably be a better idea to have the KinematicBody2D node check for collisions and then call a function on its child CanvasLayer node that increases the value.

by (1,116 points)
0 votes

You can for your own methods, but you can't for those built-in physics and collision methods. Those are methods that are only coherent inside the physics step, and you only have safe or meaningful access to these kinds of methods from inside of a _fixed_process() or _integrate_forces() call.

For your design you may want to go the other direction, and have the physics events and queries you decide on, to end with call to methods inside your CanvasLayer node script.

by (5,200 points)
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.
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 webmaster@godotengine.org with your username.