![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | trololollo78 |
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
![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | trololollo78 |
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
![]() |
Reply From: | Caresle |
You can use the signals body_entered
and body_exited
for that.
For example suppose that you have something like this
=== Scene Tree ===
Node2D
–>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:
normal_input()
else:
area_input()
move_and_slide(move)