minor refactor
This commit is contained in:
parent
f00568c781
commit
cf78507c89
@ -2,11 +2,11 @@ class_name Droplet extends RigidBody2D
|
|||||||
|
|
||||||
# default mode: a bit sluggish, tendency to pile
|
# default mode: a bit sluggish, tendency to pile
|
||||||
# bounce mode: doesn't settle down at all, but keeps flat surface
|
# bounce mode: doesn't settle down at all, but keeps flat surface
|
||||||
# bounce_wip: wonky AF, probably due to extra compute
|
# sinker: new droplet sinks, pile grows outward
|
||||||
# stick mode: piles tightly, very calm
|
# stick mode: piles tightly, very calm
|
||||||
# wip mode: interesting, the base stays together, and the new one jumps into place
|
# wip mode: interesting, the base stays together, and the new one jumps into place
|
||||||
enum Mode { DEFAULT, BOUNCE, BOUNCE_WIP, STICK, WIP }
|
enum Mode { DEFAULT, BOUNCE, SINKER, RICE, WIP }
|
||||||
const MODE: Mode = Mode.WIP
|
var MODE: Mode
|
||||||
|
|
||||||
class DropletConfig:
|
class DropletConfig:
|
||||||
var bounce
|
var bounce
|
||||||
@ -22,10 +22,10 @@ class DropletConfig:
|
|||||||
elif mode == Mode.BOUNCE:
|
elif mode == Mode.BOUNCE:
|
||||||
bounce = 0.5
|
bounce = 0.5
|
||||||
friction = 0.1
|
friction = 0.1
|
||||||
elif mode == Mode.BOUNCE_WIP:
|
elif mode == Mode.SINKER:
|
||||||
bounce = 0.5
|
bounce = 0
|
||||||
friction = 0.1
|
friction = 0.1
|
||||||
elif mode == Mode.STICK:
|
elif mode == Mode.RICE:
|
||||||
bounce = 0.1
|
bounce = 0.1
|
||||||
friction = 0.3
|
friction = 0.3
|
||||||
else: # WIP
|
else: # WIP
|
||||||
@ -44,7 +44,7 @@ func _ready():
|
|||||||
if not MODE == Mode.DEFAULT:
|
if not MODE == Mode.DEFAULT:
|
||||||
contact_monitor = true
|
contact_monitor = true
|
||||||
max_contacts_reported = 10
|
max_contacts_reported = 10
|
||||||
body_entered.connect(_on_body_entered)
|
# body_entered.connect(_on_body_entered)
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
if MODE == Mode.WIP:
|
if MODE == Mode.WIP:
|
||||||
@ -59,7 +59,7 @@ func _physics_process(delta):
|
|||||||
|
|
||||||
func _integrate_forces(state):
|
func _integrate_forces(state):
|
||||||
# this is probably overkill since we are overriding the default physics engine
|
# this is probably overkill since we are overriding the default physics engine
|
||||||
if MODE == Mode.STICK:
|
if MODE == Mode.RICE:
|
||||||
var v = state.linear_velocity
|
var v = state.linear_velocity
|
||||||
var contacts = state.get_contact_count()
|
var contacts = state.get_contact_count()
|
||||||
for i in range(contacts):
|
for i in range(contacts):
|
||||||
@ -71,18 +71,14 @@ func _integrate_forces(state):
|
|||||||
state.linear_velocity = v # self bounce
|
state.linear_velocity = v # self bounce
|
||||||
if body is RigidBody2D: # other body
|
if body is RigidBody2D: # other body
|
||||||
body.apply_central_impulse(normal * v.length() * (other_damp/contacts))
|
body.apply_central_impulse(normal * v.length() * (other_damp/contacts))
|
||||||
|
elif MODE == Mode.SINKER:
|
||||||
func _on_body_entered(body):
|
# only contribute to the target rigid bodies, let source droplet handle it's own bounce
|
||||||
if MODE == Mode.BOUNCE_WIP:
|
var v = state.linear_velocity
|
||||||
# trying to elicit stronger response from rigidBody that was struck
|
for i in range(state.get_contact_count()):
|
||||||
# ends up being kind of erratic
|
var body = state.get_contact_collider_object(i)
|
||||||
# at damp_factor .75: settles laterally, but erratic past half-full
|
var normal = state.get_contact_local_normal(i)
|
||||||
# at damp_factor of .5, it's pretty calm, but then can't overfill (expected?)
|
if body is RigidBody2D:
|
||||||
var vel = get_linear_velocity()
|
var impact_speed = v.dot(-normal)
|
||||||
const damp_factor = 0.7
|
if impact_speed > 0:
|
||||||
var normal = (body.global_position - global_position).normalized()
|
var boost = normal * impact_speed * 1
|
||||||
# reflect velocity across collision direction
|
body.apply_central_impulse(boost)
|
||||||
var bounced = vel.bounce(normal) # reflection
|
|
||||||
set_linear_velocity(bounced * damp_factor)
|
|
||||||
if body is RigidBody2D:
|
|
||||||
body.apply_central_impulse(-bounced * damp_factor)
|
|
||||||
|
|||||||
@ -1,9 +1,14 @@
|
|||||||
class_name Model extends Node2D
|
class_name Model extends Node2D
|
||||||
|
|
||||||
const PERIOD: int = 20 # smaller makes droplets faster
|
|
||||||
var CURRENT_TIME: int = 0
|
var CURRENT_TIME: int = 0
|
||||||
var last_droplet: int = 0
|
var last_droplet: int = 0
|
||||||
|
|
||||||
|
# tuning knobs
|
||||||
|
const PERIOD: int = 10 # smaller makes droplets faster
|
||||||
const DROP_PT_X = 450
|
const DROP_PT_X = 450
|
||||||
|
const DROP_PT_Y = 400
|
||||||
|
const DROP_SIZE = 2
|
||||||
|
const DROP_TYPE = Droplet.Mode.SINKER
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
pass # Replace with function body.
|
pass # Replace with function body.
|
||||||
@ -15,6 +20,7 @@ func _process(delta: float):
|
|||||||
# print("new droplet at time: ", str(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()
|
||||||
var shape = droplet.get_node("CollisionShape2D")
|
var shape = droplet.get_node("CollisionShape2D")
|
||||||
shape.shape.radius = 5
|
shape.shape.radius = DROP_SIZE
|
||||||
droplet.global_position = Vector2(DROP_PT_X, 100)
|
droplet.MODE = DROP_TYPE
|
||||||
|
droplet.global_position = Vector2(DROP_PT_X, DROP_PT_Y)
|
||||||
add_child(droplet)
|
add_child(droplet)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user