Replace imps with rigged swamp demon and adapt gait and activities
This commit is contained in:
+31
-6
@@ -3,6 +3,7 @@ var root: Node3D
|
||||
var variation=0.0
|
||||
var model
|
||||
var feet=[]
|
||||
var skin=preload("res://imp_skin.gd").new()
|
||||
var previous=Vector3.ZERO
|
||||
var phase=.1
|
||||
var clock=0.0
|
||||
@@ -15,26 +16,51 @@ const CYCLE_DISTANCE=.48
|
||||
func setup(record):
|
||||
model=record.model;root=record.root;variation=record.phase;previous=root.global_position
|
||||
feet.clear()
|
||||
skin=preload("res://imp_skin.gd").new();skin.setup(model)
|
||||
phase=.1;weight=0;body_height=0;body_rotation=Vector3.ZERO;last_direction=Vector3.ZERO
|
||||
for side in ["L","R"]:
|
||||
var leg=model.get_node("Leg"+side);var knee=leg.get_node("Knee");var foot=knee.get_node("Foot")
|
||||
feet.append({"leg":leg,"knee":knee,"foot":foot,"side":side,"anchor":foot.global_position,"target":foot.global_position,"start":foot.global_position,"landing":foot.global_position,"swing":false,"yaw":root.rotation.y,"last_phase":.1 if side=="L" else .6})
|
||||
feet.append({"width":leg.position.x+knee.position.x+foot.position.x,"forward":leg.position.z+knee.position.z+foot.position.z,"leg":leg,"knee":knee,"foot":foot,"side":side,"anchor":foot.global_position,"target":foot.global_position,"start":foot.global_position,"landing":foot.global_position,"swing":false,"yaw":root.rotation.y,"last_phase":.1 if side=="L" else .6})
|
||||
func reset():
|
||||
previous=root.global_position;weight=0;phase=.1;last_direction=Vector3.ZERO
|
||||
model.position=Vector3.ZERO;body_height=0;body_rotation=Vector3.ZERO;model.rotation=Vector3.ZERO
|
||||
for f in feet:f.leg.rotation=Vector3.ZERO;f.knee.rotation=Vector3.ZERO;f.foot.rotation=Vector3.ZERO
|
||||
for f in feet:
|
||||
f.anchor=f.foot.global_position;f.anchor.y=root.global_position.y+.06;f.target=f.anchor;f.swing=false;f.yaw=root.rotation.y
|
||||
skin.update()
|
||||
func solve(f):
|
||||
var hip=f.leg.global_position;var l1=f.knee.position.length();var l2=f.foot.position.length()
|
||||
var delta=f.target-hip;var distance=clampf(delta.length(),absf(l1-l2)+.001,l1+l2-.001)
|
||||
var direction=delta.normalized();var forward=root.global_basis.z.normalized()
|
||||
var bend=(forward-direction*forward.dot(direction)).normalized()
|
||||
var bend=(forward-direction*forward.dot(direction)).normalized()*float(model.get_meta("knee_bend",1.0))
|
||||
var along=(l1*l1-l2*l2+distance*distance)/(2*distance)
|
||||
var elbow=hip+direction*along+bend*sqrt(maxf(0,l1*l1-along*along))
|
||||
f.leg.quaternion=Quaternion(f.knee.position.normalized(),(f.leg.get_parent().to_local(elbow)-f.leg.position).normalized())
|
||||
f.knee.quaternion=Quaternion(f.foot.position.normalized(),(f.leg.to_local(f.target)-f.knee.position).normalized())
|
||||
f.foot.global_rotation=Vector3(0,f.yaw,0)
|
||||
func pose_work_hands():
|
||||
var activity=root.get_meta("activity","")
|
||||
if activity not in ["clean","mop","draw"]:return
|
||||
var t=clock
|
||||
for side in ["L","R"]:
|
||||
if side=="L" and activity!="mop":continue
|
||||
var arm=model.get_node("Arm"+side);var elbow=arm.get_node("Elbow");var hand=elbow.get_node("Hand")
|
||||
var target=Vector3(.12,.35,.57) if side=="R" else Vector3(-.12,.54,.47)
|
||||
if activity=="mop":target.z+=sin(t*3)*.10
|
||||
elif activity=="clean":target=Vector3(.30+cos(t*6)*.04,.54+sin(t*6)*.035,.54)
|
||||
else:target=Vector3(.26+cos(t*7)*.045,.84+sin(t*7)*.045,.53)
|
||||
target=root.to_global(target)
|
||||
var shoulder=arm.global_position;var l1=elbow.position.length();var l2=hand.position.length()
|
||||
var delta=target-shoulder;var distance=clampf(delta.length(),absf(l1-l2)+.001,l1+l2-.001)
|
||||
var direction=delta.normalized();target=shoulder+direction*distance
|
||||
var outward=root.global_basis.x*(-1 if side=="L" else 1)
|
||||
var bend=(outward-direction*outward.dot(direction)).normalized()
|
||||
var along=(l1*l1-l2*l2+distance*distance)/(2*distance)
|
||||
var joint=shoulder+direction*along+bend*sqrt(maxf(0,l1*l1-along*along))
|
||||
arm.quaternion=Quaternion(elbow.position.normalized(),(arm.get_parent().to_local(joint)-arm.position).normalized())
|
||||
elbow.quaternion=Quaternion(hand.position.normalized(),(arm.to_local(target)-elbow.position).normalized())
|
||||
hand.global_rotation=root.global_rotation
|
||||
arm_pose[0 if side=="L" else 1]=arm.rotation
|
||||
func update(dt,acting=false):
|
||||
dt=minf(dt,.05);clock+=dt
|
||||
var delta=root.global_position-previous;delta.y=0;previous=root.global_position
|
||||
@@ -51,7 +77,7 @@ func update(dt,acting=false):
|
||||
if moving:
|
||||
if p>=.56:
|
||||
if not f.swing:f.start=f.target;f.swing=true
|
||||
f.landing=root.global_position+root.global_basis.x*(-.135 if f.side=="L" else .135)+forward*.08;f.landing.y=ground
|
||||
f.landing=root.global_position+root.global_basis.x*f.width+forward*(f.forward+.08);f.landing.y=ground
|
||||
var t=clampf((p-.56)/.44,0,1);f.target=f.start.lerp(f.landing,smoothstep(0,1,t));f.target.y=ground+sin(t*PI)*.065
|
||||
else:
|
||||
if f.swing:f.anchor=f.landing;f.anchor.y=ground;f.swing=false;f.yaw=root.rotation.y
|
||||
@@ -77,6 +103,5 @@ func update(dt,acting=false):
|
||||
arm_pose[i]=arm_pose[i].lerp(desired,1-exp(-dt*8));arm.rotation=arm_pose[i]
|
||||
arm.get_node("Elbow").rotation.x=-.05-sin(phase*TAU+i*PI)*.045*weight
|
||||
model.get_node("Head").rotation=Vector3(sin(clock*2)*.012, sin(clock*.8+variation)*.025, -sin(phase*TAU)*.018*weight)
|
||||
var blink=absf(sin(clock*.68+variation))
|
||||
for side in ["L","R"]:model.get_node("Head/Eye"+side).scale.y=clampf(blink*24,.10,1)
|
||||
model.get_node("Tail").rotation.y=sin(clock*2.4+variation)*(.12+.08*weight)
|
||||
if acting:pose_work_hands()
|
||||
skin.update()
|
||||
|
||||
Reference in New Issue
Block a user