0 votes

hello, I'm making a game and I wanted to add a ghost mode where by pressing a key we can go through some walls (not all) and after a while it goes back to where the "physical" player is.

Godot version 3.4.4
in Engine by (24 points)

2 Answers

0 votes

Look into collision layers and collision masks.

Start by setting one or multiple collision layers on the wall objects, and matching collision mask on the player object. When the key is pressed, modify the players collision mask so that it no longer includes the walls collision layer.

Some video tutorials on collision layers:
Pigdev - Godot Engine - Collision Layer and Mask
GDQuest - Using Physics Layers and Masks in Godot 3.1 (tutorial)

by (1,085 points)

thank you i will study a little about the collision, but you know a way for when the timer out the player is teleported for the position when he was before pressing a key?

There are a lot of different ways to handle timers, and a lot of good explanations out there already. This page explains some of the most common methods: https://gdscript.com/solutions/godot-timing-tutorial/

0 votes

This is a very open ended question. How much of this have you prototyped already? Where specifically are you stuck?

If you're having trouble delineating what objects your ghost can and can't pass through, you should mess around with Collision Layers and Collision Masks. Configuring them correctly will allow physics bodies to pass through certain objects but not others. Take a look at this question for a good answer on what the difference is between a collision layer and mask:
https://godotengine.org/qa/4010/whats-difference-between-collision-layers-collision-masks
And the Collision Layers and Masks section on this page:
http://kidscancode.org/blog/2018/02/godot3_kinematic2d/

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