I have some slimes that go back and forth between a wall horizontally. I want them to jump on the icon when they get near the entity at the middle (the godot icon).
Orange line is what they're currently doing, the red line is what I want them to do.
I can get the distance to the entity, but the math involved in making the slime jump towards/on the entity then bouncing from the button is beyond me.
var velocity = Vector2.ZERO
var speed = 500
var current_speed: int = speed
var right = true
var is_regening = false
var level = 0
var power = 10
var current_experience = 0
var required_experience = 10
var button
func _ready():
button = $"../Area2D"
func _physics_process(delta: float) -> void:
$AnimatedSprite.flip_h = not right
velocity = move_and_slide(velocity, Vector2.UP)
if is_regening:
energy.current += energy.per_second * delta
current_speed = 0
$AnimatedSprite.play("idle")
else:
energy.current -= 1 * delta
current_speed = speed
$AnimatedSprite.play("walk")
if energy.current < 0:
is_regening = true
if energy.current > energy.cap:
is_regening = false
if is_on_wall():
right = !right
if right:
velocity.x = current_speed
velocity.y = 100
if not right:
velocity.x = -current_speed
velocity.y = 100
```
