-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.gd
83 lines (68 loc) · 2.68 KB
/
player.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
extends CharacterBody3D
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
const sense_horizontal = 0.5
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
var boom_force = Vector3(0,0,0)
var capture_mouse = true
@onready var anim_player = $AnimationPlayer
@onready var hitbox = $WeaponPivot/hammer_00/Hitbox
@onready var hammerplosion = $WeaponPivot/hammer_00/Hammerplosion
@onready var camera = $Pivot/SpringArm3D/Camera3D
func _ready():
$MultiplayerSynchronizer.set_multiplayer_authority(str(name).to_int())
if $MultiplayerSynchronizer.get_multiplayer_authority() == multiplayer.get_unique_id():
camera.make_current()
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func _input(event):
if event is InputEventKey and event.keycode == KEY_ESCAPE:
if capture_mouse:
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
else:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
capture_mouse != capture_mouse
if event is InputEventMouseMotion:
rotate_y(deg_to_rad(-event.relative.x * sense_horizontal))
func _physics_process(delta):
if $MultiplayerSynchronizer.get_multiplayer_authority() != multiplayer.get_unique_id():
return
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
velocity = velocity + boom_force
boom_force = Vector3(0,0,0)
move_and_slide()
func _process(delta):
if Input.is_action_just_pressed("attack"):
anim_player.play("Attack")
print("Monitoring now true")
hammerplosion.monitoring = true
func _on_animation_player_animation_finished(anim_name):
if anim_name == "Attack":
anim_player.play("Idle")
hammerplosion.monitoring = false
func _on_hitbox_area_entered(area):
print(area.get_groups())
if area.is_in_group("enemy"):
print("Enemy hit")
func _on_hammerplosion_body_entered(body):
if body.is_in_group("enemy"):
print("Enemy hit from hammer plosion")
body.hit_by_hammer(hammerplosion.global_transform.origin, 25)
func hit_by_hammer(source, force):
print("Heres the loc : ", source)
boom_force = (source - global_transform.origin).normalized() * force