Ghost mode on Godot 3d

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By akaguriookami

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.

:bust_in_silhouette: Reply From: DownloadFLD

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://forum.godotengine.org/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/

:bust_in_silhouette: Reply From: Ninfur

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)

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?

akaguriookami | 2022-07-26 12:57

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: Godot Timing Tutorial

Ninfur | 2022-07-27 06:48