Created
December 20, 2017 16:41
-
-
Save willnationsdev/5793623d3ce49011b794f67dc5e68b1f to your computer and use it in GitHub Desktop.
Simple Spaceship Propellant Motion
This file contains 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
# 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