added some bucket features and two modes
This commit is contained in:
parent
4ec4dbb5ad
commit
536b212426
@ -3,7 +3,11 @@
|
|||||||
[ext_resource type="Script" uid="uid://g0yk17km82bv" path="res://scripts/model.gd" id="1_bctr2"]
|
[ext_resource type="Script" uid="uid://g0yk17km82bv" path="res://scripts/model.gd" id="1_bctr2"]
|
||||||
[ext_resource type="Script" uid="uid://b51w6528jl7ns" path="res://scripts/droplet.gd" id="2_rka1o"]
|
[ext_resource type="Script" uid="uid://b51w6528jl7ns" path="res://scripts/droplet.gd" id="2_rka1o"]
|
||||||
|
|
||||||
|
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_qxwdg"]
|
||||||
|
bounce = 0.25
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_jsxgm"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_jsxgm"]
|
||||||
|
radius = 2.236068
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_jsxgm"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_jsxgm"]
|
||||||
size = Vector2(142, 20)
|
size = Vector2(142, 20)
|
||||||
@ -12,7 +16,8 @@ size = Vector2(142, 20)
|
|||||||
script = ExtResource("1_bctr2")
|
script = ExtResource("1_bctr2")
|
||||||
|
|
||||||
[node name="droplet" type="RigidBody2D" parent="." unique_id=1124928337]
|
[node name="droplet" type="RigidBody2D" parent="." unique_id=1124928337]
|
||||||
position = Vector2(100, 100)
|
position = Vector2(27, 96)
|
||||||
|
physics_material_override = SubResource("PhysicsMaterial_qxwdg")
|
||||||
script = ExtResource("2_rka1o")
|
script = ExtResource("2_rka1o")
|
||||||
metadata/_edit_group_ = true
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
@ -54,7 +59,7 @@ shape = SubResource("RectangleShape2D_jsxgm")
|
|||||||
debug_color = Color(0.5959702, 0.54461277, 0.08352526, 0.41960785)
|
debug_color = Color(0.5959702, 0.54461277, 0.08352526, 0.41960785)
|
||||||
|
|
||||||
[node name="bucket" type="Node2D" parent="." unique_id=431072106]
|
[node name="bucket" type="Node2D" parent="." unique_id=431072106]
|
||||||
position = Vector2(-98, 102)
|
position = Vector2(276, -261)
|
||||||
metadata/_edit_group_ = true
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
[node name="platform4" type="StaticBody2D" parent="bucket" unique_id=1216137882]
|
[node name="platform4" type="StaticBody2D" parent="bucket" unique_id=1216137882]
|
||||||
@ -86,3 +91,49 @@ metadata/_edit_group_ = true
|
|||||||
position = Vector2(-0.8749161, 0.48425293)
|
position = Vector2(-0.8749161, 0.48425293)
|
||||||
shape = SubResource("RectangleShape2D_jsxgm")
|
shape = SubResource("RectangleShape2D_jsxgm")
|
||||||
debug_color = Color(0.5959702, 0.54461277, 0.08352526, 0.41960785)
|
debug_color = Color(0.5959702, 0.54461277, 0.08352526, 0.41960785)
|
||||||
|
|
||||||
|
[node name="big_bucket" type="Node2D" parent="." unique_id=1340688088]
|
||||||
|
position = Vector2(-115, 91)
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="platform4" type="StaticBody2D" parent="big_bucket" unique_id=1712494835]
|
||||||
|
position = Vector2(450.99997, 440)
|
||||||
|
rotation = 1.5717075
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="big_bucket/platform4" unique_id=1527990798]
|
||||||
|
position = Vector2(-0.8749161, 0.48425293)
|
||||||
|
shape = SubResource("RectangleShape2D_jsxgm")
|
||||||
|
debug_color = Color(0.5959702, 0.54461277, 0.08352526, 0.41960785)
|
||||||
|
|
||||||
|
[node name="platform5" type="StaticBody2D" parent="big_bucket" unique_id=1995856626]
|
||||||
|
position = Vector2(512, 498.99997)
|
||||||
|
rotation = 0.0012022424
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="big_bucket/platform5" unique_id=1305563426]
|
||||||
|
position = Vector2(-0.8749161, 0.48425293)
|
||||||
|
shape = SubResource("RectangleShape2D_jsxgm")
|
||||||
|
debug_color = Color(0.5959702, 0.54461277, 0.08352526, 0.41960785)
|
||||||
|
|
||||||
|
[node name="platform7" type="StaticBody2D" parent="big_bucket" unique_id=146253526]
|
||||||
|
position = Vector2(650, 498.99997)
|
||||||
|
rotation = 0.00064454623
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="big_bucket/platform7" unique_id=1359956789]
|
||||||
|
position = Vector2(-0.8749161, 0.48425293)
|
||||||
|
shape = SubResource("RectangleShape2D_jsxgm")
|
||||||
|
debug_color = Color(0.5959702, 0.54461277, 0.08352526, 0.41960785)
|
||||||
|
|
||||||
|
[node name="platform6" type="StaticBody2D" parent="big_bucket" unique_id=749418854]
|
||||||
|
position = Vector2(710.00006, 437.00003)
|
||||||
|
rotation = -1.5774848
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="big_bucket/platform6" unique_id=1171236966]
|
||||||
|
position = Vector2(-0.8749161, 0.48425293)
|
||||||
|
shape = SubResource("RectangleShape2D_jsxgm")
|
||||||
|
debug_color = Color(0.5959702, 0.54461277, 0.08352526, 0.41960785)
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="droplet" to="droplet" method="_on_body_entered"]
|
||||||
|
|||||||
@ -1,7 +1,49 @@
|
|||||||
class_name Droplet extends RigidBody2D
|
class_name Droplet extends RigidBody2D
|
||||||
|
|
||||||
func _ready():
|
# bounce mode seems to settle with a consistent surface, but is erratic
|
||||||
pass # Replace with function body.
|
# stick mode seems to make sand castles, but is very calm
|
||||||
|
enum Mode { BOUNCE, STICK }
|
||||||
|
const mode: Mode = Mode.BOUNCE
|
||||||
|
|
||||||
func _process(delta):
|
func _ready():
|
||||||
|
var mat = PhysicsMaterial.new()
|
||||||
|
mat.bounce = .1 if mode == Mode.BOUNCE else 0
|
||||||
|
mat.friction = 0.0
|
||||||
|
physics_material_override = mat
|
||||||
|
|
||||||
|
# setup body entered signal, seems to also matter for STICK mode
|
||||||
|
contact_monitor = true
|
||||||
|
max_contacts_reported = 10
|
||||||
|
body_entered.connect(_on_body_entered)
|
||||||
|
|
||||||
|
func _physics_process(delta):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
func _integrate_forces(state):
|
||||||
|
if mode == Mode.STICK:
|
||||||
|
var v = state.linear_velocity
|
||||||
|
var contacts = state.get_contact_count()
|
||||||
|
for i in range(contacts):
|
||||||
|
var body = state.get_contact_collider_object(i)
|
||||||
|
var normal = state.get_contact_local_normal(i)
|
||||||
|
var self_damp = .9
|
||||||
|
var other_damp = 1 - self_damp
|
||||||
|
v = v.bounce(normal) * self_damp
|
||||||
|
state.linear_velocity = v # self bounce
|
||||||
|
if body is RigidBody2D: # other body
|
||||||
|
body.apply_central_impulse(normal * v.length() * (other_damp/contacts))
|
||||||
|
|
||||||
|
func _on_body_entered(body):
|
||||||
|
if mode == Mode.BOUNCE:
|
||||||
|
# trying to elicit stronger response from rigidBody that was struck
|
||||||
|
# ends up being kind of erratic
|
||||||
|
# at damp_factor .75: settles laterally, but erratic past half-full
|
||||||
|
# at damp_factor of .5, it's pretty calm, but then can't overfill (expected?)
|
||||||
|
var vel = get_linear_velocity()
|
||||||
|
const damp_factor = 0.7
|
||||||
|
var normal = (body.global_position - global_position).normalized()
|
||||||
|
# reflect velocity across collision direction
|
||||||
|
var bounced = vel.bounce(normal) # reflection
|
||||||
|
set_linear_velocity(bounced * damp_factor)
|
||||||
|
if body is RigidBody2D:
|
||||||
|
body.apply_central_impulse(-bounced * damp_factor)
|
||||||
|
|||||||
@ -1,15 +1,19 @@
|
|||||||
class_name Model extends Node2D
|
class_name Model extends Node2D
|
||||||
|
|
||||||
const PERIOD: int = 300
|
const PERIOD: int = 20 # smaller makes droplets faster
|
||||||
var CURRENT_TIME: int = 0
|
var CURRENT_TIME: int = 0
|
||||||
|
var last_droplet: int = 0
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
pass # Replace with function body.
|
pass # Replace with function body.
|
||||||
|
|
||||||
func _process(delta: float):
|
func _process(delta: float):
|
||||||
CURRENT_TIME += delta * 100
|
CURRENT_TIME += delta * 100
|
||||||
if CURRENT_TIME % 100 == 0:
|
if CURRENT_TIME - last_droplet > PERIOD:
|
||||||
print("Current time: ", str(CURRENT_TIME))
|
last_droplet = CURRENT_TIME
|
||||||
|
# print("new droplet at time: ", str(CURRENT_TIME))
|
||||||
var droplet = preload("res://scenes/droplet.tscn").instantiate()
|
var droplet = preload("res://scenes/droplet.tscn").instantiate()
|
||||||
droplet.global_position = Vector2(100, 100)
|
var shape = droplet.get_node("CollisionShape2D")
|
||||||
|
shape.shape.radius = 5
|
||||||
|
droplet.global_position = Vector2(450, 100)
|
||||||
add_child(droplet)
|
add_child(droplet)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user