Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- var curHP : int = 100
- var maxHP : int = 100
- var ammo : int = 69
- var score : int = 0
- enum IN_BODY {
- AIR,
- TOXIC,
- IRRADIATED,
- WATER,
- LAVA,
- SWAMP,
- OIL
- }
- #References
- onready var head = $Head
- onready var foot = $Feet/Foot
- #Mouse and Keyboard variables
- export var mouse_sensitivity = 1.0
- var input_direction = Vector3.ZERO
- #Physics variables
- export var max_speed = 8
- export var acceleration = 8
- export var deacceleration = 4
- export var air_control = 0.0
- export var jump_height = 9.8
- export var gravity = 9.8
- export var max_slope = 75
- export var ignore_rotation = false
- var movement_vector = Vector3.ZERO
- var direction = Vector3.ZERO
- var drag = 0.0
- var gravity_vector = Vector3.ZERO
- var snap =Vector3.ZERO
- var onground = false
- #signal movement_info
- var frozen = false
- var body_to_move: KinematicBody
- func _ready():
- Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
- print("CAPTURED")
- drag = float(acceleration) / float(max_speed)
- func _initialize(_body_to_move: KinematicBody):
- pass
- func _input(event):
- #Mouse Input
- if event is InputEventMouseMotion:
- rotate_y(deg2rad(-event.relative.x * mouse_sensitivity)) # * get_physics_process_delta_time())
- head.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity)) # * get_physics_process_delta_time())
- head.rotation.x = clamp(head.rotation.x, deg2rad(-90), deg2rad(90))
- #Keyboard Input
- input_direction = global_transform.basis.x * (- int(Input.is_action_pressed("left")) + int(Input.is_action_pressed("right"))) + global_transform.basis.z * (- int(Input.is_action_pressed("forward")) + int(Input.is_action_pressed("backward")))
- input_direction = input_direction.normalized()
- if Input.is_action_just_pressed("jump") and (is_on_floor() or _ground_check()):
- print("JUMPED")
- _dash_to_direction(Vector3.UP, jump_height, gravity)
- func _physics_process(delta):
- _gravity(delta)
- _move(delta)
- func _move(delta):
- var target_movement_vector = input_direction * max_speed
- movement_vector = movement_vector.linear_interpolate(target_movement_vector, acceleration * delta)
- movement_vector = move_and_slide_with_snap(movement_vector, snap, Vector3.UP, true, 4, deg2rad(max_slope), true)
- func _gravity(delta):
- if !is_on_floor() and !_ground_check():
- gravity_vector += Vector3.DOWN * gravity * delta #gravity_vector += Vector3.DOWN * 0.5 * gravity * delta * delta
- elif is_on_floor() or _ground_check():
- gravity_vector = - get_floor_normal() * gravity
- else:
- gravity_vector = - get_floor_normal()
- gravity_vector = move_and_slide_with_snap(gravity_vector, snap, Vector3.UP, true, 4, deg2rad(max_slope), true)
- func _ground_check():
- if foot.is_colliding(): return true
- #may change variable names
- func _dash_to_direction(dir: Vector3, target: float, magnitude: float):
- dir = dir.normalized()
- movement_vector += dir * sqrt(target * 2 * magnitude)
- print(" y_vel -> ", movement_vector.y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement