mirror of
https://github.com/creyD/ludum_dare_46.git
synced 2026-06-13 22:12:23 +02:00
Added beginnings of boss
This commit is contained in:
24
src/Autoloads/Steering.gd
Normal file
24
src/Autoloads/Steering.gd
Normal file
@@ -0,0 +1,24 @@
|
||||
extends Node
|
||||
|
||||
const DEFAULT_MASS = 2.0
|
||||
const DEFAULT_SLOW_RADIUS = 200.0
|
||||
const DEFAULT_MAX_SPEED = 300.0
|
||||
|
||||
func arrive_to(velocity,
|
||||
position_current,
|
||||
position_target,
|
||||
mass=DEFAULT_MASS,
|
||||
slow_radius=DEFAULT_SLOW_RADIUS,
|
||||
max_speed=DEFAULT_MAX_SPEED):
|
||||
"""
|
||||
Calculates and returns a new velocity with the arrive steering behavior arrived based on
|
||||
an existing velocity (Vector2), the object's current and target positions (Vector2)
|
||||
"""
|
||||
var distance_to_target = position_current.distance_to(position_target)
|
||||
|
||||
var desired_velocity = (position_target - position_current).normalized() * max_speed
|
||||
if distance_to_target < slow_radius:
|
||||
desired_velocity *= (distance_to_target / slow_radius) * .75 + .25
|
||||
var steering = (desired_velocity - velocity) / mass
|
||||
|
||||
return velocity + steering
|
||||
Reference in New Issue
Block a user