do rope things

This commit is contained in:
mightypanders 2021-06-13 15:43:34 +02:00
parent b6234e082a
commit d7747b4979
2 changed files with 37 additions and 2 deletions

33
Rope.gd Normal file
View File

@ -0,0 +1,33 @@
extends RigidBody2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var anchor_ahead
# Called when the node enters the scene tree for the first time.
func _ready():
mode = RigidBody2D.MODE_STATIC
pass # Replace with function body.
func start():
mode = RigidBody2D.MODE_KINEMATIC
func _physics_process(delta):
if mode == RigidBody2D.MODE_STATIC:
if anchor_ahead != null:
var rot_dir = get_angle_to(anchor_ahead.global_position)
rotation += (rot_dir)
global_position = (anchor_ahead.global_position + Vector2(10,0))
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if mode == RigidBody2D.MODE_STATIC:
if anchor_ahead != null:
var rot_dir = get_angle_to(anchor_ahead.global_position)
rotation += (rot_dir)
global_position = (anchor_ahead.global_position + Vector2(10,0))
pass

View File

@ -1,12 +1,14 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://assets/placeholder_white.png" type="Texture" id=1]
[ext_resource path="res://Rope.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 1, 10 )
[node name="Rope" type="RigidBody2D"]
position = Vector2( 0, 6 )
position = Vector2( 0, 10 )
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
modulate = Color( 0.423529, 0.176471, 0, 1 )