Skip to content

Instantly share code, notes, and snippets.

@willnationsdev
Created December 20, 2017 16:41
Show Gist options
  • Save willnationsdev/5793623d3ce49011b794f67dc5e68b1f to your computer and use it in GitHub Desktop.
Save willnationsdev/5793623d3ce49011b794f67dc5e68b1f to your computer and use it in GitHub Desktop.
Simple Spaceship Propellant Motion
# stolen from Discord's igalencar's message in #programming channel
extends KinematicBody2D
const MAX_SPEED = 300
const MAX_FORCE = 0.02
var velocity = Vector2()
onready var target = get_position()
func _ready():
pass
func _process(delta):
velocity = steer(target)
move_and_collide(velocity * delta)
target = get_viewport().get_mouse_position()
pass
func steer(target):
var desired_velocity = Vector2(target - get_position()).normalized()* MAX_SPEED
var steer = desired_velocity - velocity
var target_velocity = velocity + (steer * MAX_FORCE)
return(target_velocity)
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment