Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- const DECAY = 0.5
- const SDECAY = 1
- const ACC = 1
- const SACC = 3
- const LIMIT = 10
- const SLIMIT = 30
- var gravity = Vector3.DOWN * 25
- var jumpspeed = 10
- var sjumpspeed = 20
- var jump = 0
- var spin = 0.1
- var xacc = 0
- var zacc = 0
- var yacc = 0
- var sprint = false
- var motion = Vector3(0, 0, 0)
- var camera = null
- func _ready():
- camera = get_tree().get_root().get_camera()
- func _physics_process(delta):
- motion += gravity * delta
- get_input()
- motion = move_and_slide(motion, Vector3.UP)
- run_decay()
- if jump == 1 and (is_on_floor() or get_wall_jump()):
- motion.y = jumpspeed
- elif jump == 2 and (is_on_floor() or get_wall_jump()):
- motion.y = sjumpspeed
- var bodies = get_slide_collision(1)
- func get_input():
- var vy = motion.y
- motion = Vector3()
- jump = 0
- if Input.is_action_just_pressed("ui_accept"):
- if Input.is_key_pressed(KEY_SHIFT):
- jump = 2
- else:
- jump = 1
- if Input.is_key_pressed(KEY_W):
- if Input.is_key_pressed(KEY_SHIFT) and is_on_floor():
- sprint = true
- if xacc < SLIMIT and xacc > -SLIMIT:
- xacc-= SACC
- else:
- sprint = false
- if xacc < LIMIT and xacc > -LIMIT:
- xacc-=ACC
- elif Input.is_key_pressed(KEY_S):
- if Input.is_key_pressed(KEY_SHIFT) and is_on_floor():
- sprint = true
- if xacc < SLIMIT and xacc > -SLIMIT:
- xacc+= SACC
- else:
- sprint = false
- if xacc < LIMIT and xacc > -LIMIT:
- xacc+=ACC
- if Input.is_key_pressed(KEY_D):
- if Input.is_key_pressed(KEY_SHIFT) and is_on_floor():
- sprint = true
- if zacc < SLIMIT and zacc > -SLIMIT:
- zacc+= SACC
- else:
- sprint = false
- if zacc < LIMIT and zacc > -LIMIT:
- zacc += ACC
- elif Input.is_key_pressed(KEY_A):
- if Input.is_key_pressed(KEY_SHIFT) and is_on_floor():
- sprint = true
- if zacc < SLIMIT and zacc > -SLIMIT:
- zacc-= SACC
- else:
- sprint = false
- if zacc < LIMIT and zacc > -LIMIT:
- zacc-= ACC
- motion.y = vy
- motion += transform.basis.x * (0-zacc)
- motion += transform.basis.z * (0-xacc)
- func _unhandled_input(event):
- if event is InputEventMouseMotion:
- rotate_y(-lerp(0, spin, event.relative.x/10))
- if camera != null:
- camera.rotate_x(lerp(0, spin, event.relative.y/50))
- func get_wall_jump():
- var bodies = get_slide_collision(1)
- print(bodies == null)
- if bodies != null:
- if bodies.collider.name != null and not is_on_floor():
- return true
- else:
- return false
- else:
- return false
- func run_decay():
- var d = 0
- if sprint:
- d = SDECAY
- else:
- d = DECAY
- if xacc < 0:
- xacc += d
- elif xacc > 0:
- xacc -= d
- if zacc < 0:
- zacc += d
- elif zacc > 0:
- zacc -= d
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement