Last active
June 4, 2018 03:17
-
-
Save securas/e788335dee116f9301e11f2d3df59fdf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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