2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
extends RigidBody
|
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
# member variables
|
2014-02-10 01:10:30 +00:00
|
|
|
const STATE_WALKING = 0
|
|
|
|
const STATE_DYING = 1
|
|
|
|
|
|
|
|
var prev_advance = false
|
|
|
|
var deaccel = 20.0
|
|
|
|
var accel = 5
|
|
|
|
var max_speed = 2
|
|
|
|
var rot_dir = 4
|
|
|
|
var rot_speed = 1
|
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
var dying = false
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
func _integrate_forces(state):
|
2014-02-10 01:10:30 +00:00
|
|
|
var delta = state.get_step()
|
|
|
|
var lv = state.get_linear_velocity()
|
|
|
|
var g = state.get_total_gravity()
|
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
lv += g*delta # apply gravity
|
2014-02-10 01:10:30 +00:00
|
|
|
var up = -g.normalized()
|
|
|
|
|
|
|
|
if (dying):
|
|
|
|
state.set_linear_velocity(lv)
|
|
|
|
return
|
2015-12-09 07:38:23 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
for i in range(state.get_contact_count()):
|
|
|
|
var cc = state.get_contact_collider_object(i)
|
|
|
|
var dp = state.get_contact_local_normal(i)
|
2015-12-09 07:38:23 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (cc):
|
|
|
|
if (cc extends preload("res://bullet.gd") and not cc.disabled):
|
|
|
|
set_mode(MODE_RIGID)
|
2015-12-09 07:38:23 +00:00
|
|
|
dying = true
|
|
|
|
#lv = s.get_contact_local_normal(i)*400
|
|
|
|
state.set_angular_velocity(-dp.cross(up).normalized()*33.0)
|
2014-02-10 01:10:30 +00:00
|
|
|
get_node("AnimationPlayer").play("impact")
|
|
|
|
get_node("AnimationPlayer").queue("explode")
|
2015-05-04 21:30:57 +00:00
|
|
|
set_friction(1)
|
2015-12-09 07:38:23 +00:00
|
|
|
cc.disabled = true
|
2014-02-10 01:10:30 +00:00
|
|
|
get_node("sound").play("hit")
|
|
|
|
return
|
|
|
|
|
|
|
|
var col_floor = get_node("Armature/ray_floor").is_colliding()
|
|
|
|
var col_wall = get_node("Armature/ray_wall").is_colliding()
|
|
|
|
|
|
|
|
var advance = not col_wall and col_floor
|
|
|
|
|
|
|
|
var dir = get_node("Armature").get_transform().basis[2].normalized()
|
|
|
|
var deaccel_dir = dir
|
|
|
|
|
|
|
|
if (advance):
|
|
|
|
if (dir.dot(lv) < max_speed):
|
2015-12-09 07:38:23 +00:00
|
|
|
lv += dir*accel*delta
|
2014-02-10 01:10:30 +00:00
|
|
|
deaccel_dir = dir.cross(g).normalized()
|
|
|
|
else:
|
|
|
|
if (prev_advance):
|
2015-12-09 07:38:23 +00:00
|
|
|
rot_dir = 1 # randf()*2.0 - 1.0
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
dir = Matrix3(up, rot_dir*rot_speed*delta).xform(dir)
|
|
|
|
get_node("Armature").set_transform(Transform().looking_at(-dir, up))
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
var dspeed = deaccel_dir.dot(lv)
|
2015-12-09 07:38:23 +00:00
|
|
|
dspeed -= deaccel*delta
|
|
|
|
if (dspeed < 0):
|
|
|
|
dspeed = 0
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
lv = lv - deaccel_dir*deaccel_dir.dot(lv) + deaccel_dir*dspeed
|
|
|
|
|
|
|
|
state.set_linear_velocity(lv)
|
2015-12-09 07:38:23 +00:00
|
|
|
prev_advance = advance
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
|
2015-08-28 18:15:31 +00:00
|
|
|
func _die():
|
|
|
|
queue_free()
|