Skip to content

Instantly share code, notes, and snippets.

@securas
Last active June 4, 2018 03:17
Show Gist options
  • Save securas/e788335dee116f9301e11f2d3df59fdf to your computer and use it in GitHub Desktop.
Save securas/e788335dee116f9301e11f2d3df59fdf to your computer and use it in GitHub Desktop.
# Update the object velocity with vel += steering( position, target_position, vel, delta )
# adjust MAX_VEL and MAX_FORCE values to control how the motion looks like
func steering( cur_pos, target_pos, cur_vel, delta ):
var distance_to_target = target_pos - cur_pos
var desired_vel = distance_to_target.normalized() * MAX_VEL
steering_force = ( desired_vel - cur_vel ) / delta
steering_force = steering_force.clamped( MAX_FORCE )
return steering_force * delta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment