Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- const SPEED_MULTIPLIER = 2
- const STRAFE_MULTIPLIER = 1.5
- func _ready():
- set_fixed_process(true)
- func _fixed_process(delta):
- update()
- # rotation
- var mouse_pos = get_viewport().get_mouse_pos()
- var rot = get_angle_to(mouse_pos) + self.get_rot()
- set_rot(rot)
- # movement
- var player_pos = self.get_pos()
- if Input.is_action_pressed("strafe_left"):
- move((mouse_pos - player_pos).normalized().tangent() * STRAFE_MULTIPLIER)
- if Input.is_action_pressed("strafe_right"):
- move((player_pos - mouse_pos).normalized().tangent() * STRAFE_MULTIPLIER)
- if Input.is_action_pressed("move_forward"):
- move((mouse_pos - player_pos).normalized() * SPEED_MULTIPLIER)
- if Input.is_action_pressed("move_backward"):
- move((player_pos - mouse_pos).normalized() * SPEED_MULTIPLIER)
- # actions
- if Input.is_action_pressed("primary_fire"):
- var space_state = get_world_2d().get_direct_space_state()
- var result = space_state.intersect_ray(player_pos, mouse_pos, [ self ])
- if (not result.empty()):
- print("Hit at point: ",result.position)
- if Input.is_action_pressed("jump"):
- print ("JUMPING")
- func _draw():
- draw_line(self.get_pos(), get_viewport().get_mouse_pos(), Color(255, 0, 0), 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement