Wind mechanic help

Godot Version

4.2.2

Question

I am trying to make wind push a characterbody 2D using an area 2D but I don’t know how to apply a force to the characterbody. I’ve gotten as far as to connect the character and the area2D using signals but I don’t what to when the character enters the area2d. For reference I’m making a top down game based on the wind puzzle mechanic in zelda games and I want the wind to slowly push the player back but not slow enough to allow them to get to the other end.

You could add a new “wind” variable to the CharacterBody2D’s velocity.

Could you give me an example or some instructions on how to do this as I’m very new to godot and don’t how to do it.
This is my code at the moment:

You have a variable for speed try making a variable for wind_push and add that to your final velocity calculation.

Make sure to paste scripts instead of screenshots and use formatting like so with the </> button or ctrl+e on the forum

```
type or paste code here
```

@export var speed: float = 35
var wind_push := Vector2.ZERO

func _physics_process(delta: float) -> void:
    var moveDirection = Input.get_vector("left", "right", "up", "down")
    velocity = moveDirection * speed + wind_push

func _on_wind_body_entered(body) -> void:
    wind_push = Vector2(50, 0) # hard-coded value is bad, may look into get_meta?

func _on_wind_body_exited(body) -> void:
    wind_push = Vector2.ZERO
1 Like

It worked, thank you so much :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.