0 votes

Hi, I'm new to godot and I have a question, How do I make my character in a specific area change the controls, gravity and speed

in Engine by (12 points)

1 Answer

0 votes

You can use the signals body_entered and body_exited for that.

For example suppose that you have something like this
=== Scene Tree ===
-->Area2D [Area Script]
-->Player (KinematicBody2D) [Player Script]

In your Area2D click in Node section(Next to Inspector in default layout)
Then click in body_entered and then connect to your Area2D script

Example in how to change the speed

func _on_Area2D_body_entered(body):
    body.speed = 50

Now connect the body_exited signal to the Area2D (like you did with body_entered) and change the speed back to its normal value

func _on_Area2D_body_exited(body):
    body.speed = 25

Use the same logic for change the controls and gravity.

For change the controls you can create two separate methods like normal_input() area_input() and add a variable that check what is the current input.

Something like this.

var is_normal_input = true

func normal_input():
    # normal input logic
    if Input.is_action_pressed("ui_left"): # player move to left

func second_input():
    # use different logic here for example
    if Input.is_action_pressed("ui_space"): # player move to left

func _physics_process(delta):
    if is_normal_input:
by (50 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.