diff options
author | cflip <cflip@cflip.net> | 2022-09-23 17:23:06 -0600 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2022-09-23 17:23:06 -0600 |
commit | ed3b37f6fa7b37429f79a7d229e1134ae316ed7e (patch) | |
tree | e8424d06ac364327c32e18899bc7d837d042bb66 | |
parent | c46bb2fca39de21df9c4abbdc9cbbf2262e8ace0 (diff) |
Replace the basketball sprite object with a RigidBody2D
This way we don't have to implement all of the physics ourselves.
-rw-r--r-- | Basketball.gd (renamed from Sprite.gd) | 12 | ||||
-rw-r--r-- | basketball.tscn | 21 | ||||
-rw-r--r-- | project.godot | 1 |
3 files changed, 20 insertions, 14 deletions
diff --git a/Sprite.gd b/Basketball.gd index ce3a8de..31642ae 100644 --- a/Sprite.gd +++ b/Basketball.gd @@ -1,26 +1,20 @@ -extends Sprite - -export var gravity = 15 +extends RigidBody2D var angular_speed = PI -var velocity = Vector2(500, -800) - var start_position # Called when the node enters the scene tree for the first time. func _ready(): start_position = position + apply_central_impulse(Vector2(500, -800)) pass # Replace with function body. # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): - position += velocity * delta rotation += angular_speed * delta - velocity.y += gravity - func _input(event): if event.is_action_pressed("shoot"): position = start_position rotation = 0 - velocity = Vector2(500, -800) + apply_central_impulse(Vector2(500, -800)) diff --git a/basketball.tscn b/basketball.tscn index 2c8edf4..c7203d2 100644 --- a/basketball.tscn +++ b/basketball.tscn @@ -1,10 +1,21 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://ballforbasketing.png" type="Texture" id=1] -[ext_resource path="res://Sprite.gd" type="Script" id=2] +[ext_resource path="res://Basketball.gd" type="Script" id=2] -[node name="Sprite" type="Sprite"] -position = Vector2( 114, 478 ) +[sub_resource type="CircleShape2D" id=1] +radius = 40.0 + +[node name="Basketball" type="RigidBody2D"] +position = Vector2( 71, 541 ) +script = ExtResource( 2 ) +__meta__ = { +"_edit_group_": true +} + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) + +[node name="Sprite" type="Sprite" parent="."] scale = Vector2( 5, 5 ) texture = ExtResource( 1 ) -script = ExtResource( 2 ) diff --git a/project.godot b/project.godot index 56cf31e..b05b1de 100644 --- a/project.godot +++ b/project.godot @@ -29,6 +29,7 @@ shoot={ [physics] common/enable_pause_aware_picking=true +2d/default_gravity=981 [rendering] |