Don't code before bed
This commit is contained in:
parent
51821a6299
commit
023a9ed61e
@ -1,23 +1,44 @@
|
|||||||
extends CharacterBody2D
|
extends CharacterBody2D
|
||||||
|
|
||||||
const MAGNET_FORCE = 100
|
const MAGNET_FORCE: int = 1000
|
||||||
|
|
||||||
|
@export var acceleration: Vector2 = Vector2.ZERO
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
add_to_group("magnets")
|
add_to_group("magnets")
|
||||||
max_slides = 1
|
max_slides = 1
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
var acceleration: Vector2 = Vector2()
|
acceleration = Vector2()
|
||||||
|
|
||||||
#calc direction
|
#calc acceleration to other magnets
|
||||||
for iter in get_tree().get_nodes_in_group("magnets"):
|
for iter in get_tree().get_nodes_in_group("magnets"):
|
||||||
if iter == self:
|
if iter == self:
|
||||||
continue
|
continue
|
||||||
acceleration += (iter.position - position).normalized() * MAGNET_FORCE
|
|
||||||
|
var dir: Vector2 = (iter.position - position).normalized()
|
||||||
|
var dist: float = (iter.position - position).length()
|
||||||
|
|
||||||
|
acceleration += dir * (MAGNET_FORCE / dist)
|
||||||
|
|
||||||
|
#if moving, rotate to face that direction
|
||||||
|
if velocity >= Vector2.ONE:
|
||||||
|
var dest: float = acceleration.angle() + TAU/4
|
||||||
|
var change: float = dest - rotation
|
||||||
|
|
||||||
|
var decimal: float = change - snapped(change, 1)
|
||||||
|
|
||||||
|
print (change, " : ", 1 - decimal)
|
||||||
|
|
||||||
|
#rotate faster when closer to 0
|
||||||
|
rotate(lerp(0.0, change, 1 - decimal) * delta)
|
||||||
|
|
||||||
|
#NOTE: this doesn't work the way I want it to ;_;
|
||||||
|
|
||||||
#apply to velocity
|
#apply to velocity
|
||||||
velocity += acceleration * delta
|
velocity += acceleration * delta
|
||||||
var collided: bool = move_and_slide()
|
|
||||||
|
|
||||||
|
#move and stop on collision
|
||||||
|
var collided: bool = move_and_slide()
|
||||||
if collided:
|
if collided:
|
||||||
velocity = Vector2.ZERO
|
velocity = Vector2.ZERO
|
||||||
|
Loading…
x
Reference in New Issue
Block a user