0 votes

I am new to GDscript and Godot and coding in general. I put the player's scene and the environment into one main scene. I have a few questions:
1. How do I reference an object(CSGbox) from another scene into a player movement script linked to the player (kinematic body) in another scene?
2. What code do I use to detect if my player collides with the object referred to in question 1 from the other scene.
I am planning to make a bounce pad/trampoline kind of thing. My code will be something like this: if the player is in contact with the bounce pad, it will change the variable jump speed to 1000 and automatically jump into the air, acting as a launch pad. And immediately change the jump speed back to the original value after jumping.

Godot version 3.4.2
in Engine by (16 points)

I don't quite understand but I think you are talking about collision
did you use "Area3d"

You can make global script for your player or you can adress the node which you want to use like:
onready var Bounce-pad-variables = getnode("/root/Level1/bounccepad") or
onready var Player-variables = getparent.getchild.get_node("player")

For detecting collision you can use signals from Area2D(On the right side of the inspector press "node" and you can pick a signal ).
For specific items you can either use groups
func onbounceareaareaentered(area)
if area.isingroup("push"):
or
if area =="player"

No, I didn't use an area node the kinematic body along with the mesh instance, collision shape and the camera, etc. does fine. Is that needed to do this?

1 Answer

0 votes

Long story short, you probably want signals: https://docs.godotengine.org/en/stable/getting_started/step_by_step/signals.html

First of all, for the Player and Box to be available to each other, they will both be under some mutual parent node anyway, so they are in the SceneTree when you play. One way or another, it's clear they can probably find each other.

Anyway, add your CSGBox to the scene. Then add an Area node on top of that. Then add a CollisionShape on that Area node, and set it's shape to "box" in the inspector; it should just fit the box immediately. Now click on the Area node, and find the "node" tab, and you should see all the signals it can do. Choose one like "area entered" and choose your player in the dialog that comes up to connect it to. Your player script will automatically fill with the function that will be called when something collides with that CSGBox.

To make sure it only works with the player, one way is to add a class_name Player or something to the top of your player script, and in the area_entered callback, make sure you check if body is Player before you do anything, or check the node's name, etc.

by (170 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 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.