Godot Version
Godot 4.3`
Question
I want to create an ennemie that follow my player but also hve gravity but some how i can’t make my ennemie to be affected by the gravity
This is my code:
extends CharacterBody2D
const gravity = 1650
@onready var player = get_node(“/root/World/Player”)
func _physics_process(delta: float) → void:
# Get the direction to the player
var direction = global_position.direction_to(player.global_position)
velocity = direction * 300.0 # Apply movement toward the player
# Apply gravity only if the enemy is not on the ground
if not is_on_floor(): # Checks if the character is not standing on the ground
velocity.y += gravity * delta
else:
velocity.y = 0 # Prevent the enemy from floating when on the ground
# Use move_and_slide, which automatically handles velocity and up direction in Godot 4.3
move_and_slide()