clean code, disable jump, disable debug message

This commit is contained in:
AleaJactaEst 2022-02-03 22:19:58 +01:00
parent e398c8d8e1
commit 318fec80ee
2 changed files with 38 additions and 42 deletions

View file

@ -6,16 +6,7 @@ extends CharacterBody3D
# | # |
# Down # Down
#const SPEED = 5.0 # Constant
const JUMP_FORCE = 4.5
# Get the gravity from the project settings to be synced with RigidDynamicBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
var starting_point = Vector2(DisplayServer.window_get_size().x / 2, DisplayServer.window_get_size().y / 2)
var camera_rotate_y = 0.0
var camera_rotate_x = 0.0
var player_rotate_y = 0.0
const SPEED_WALK_UP = 5.0 const SPEED_WALK_UP = 5.0
const SPEED_WALK_UP_STRAFE = 3.0 const SPEED_WALK_UP_STRAFE = 3.0
const SPEED_WALK_STRAFE = 2.5 const SPEED_WALK_STRAFE = 2.5
@ -28,17 +19,22 @@ const SPEED_RUN_STRAFE = SPEED_WALK_STRAFE * 2.0
const SPEED_RUN_DOWN_STRAFE = SPEED_WALK_DOWN_STRAFE * 2.0 const SPEED_RUN_DOWN_STRAFE = SPEED_WALK_DOWN_STRAFE * 2.0
const SPEED_RUN_DOWN = SPEED_WALK_DOWN * 2.0 const SPEED_RUN_DOWN = SPEED_WALK_DOWN * 2.0
#const SPEED_WALK = 5.0
#const SPEED_RUN = 10.0
#const MUL_SPEED_STRAFE = 0.5
#const MUL_SPEED_DOWN = 0.2
const SPEED_ROTATE = PI const SPEED_ROTATE = PI
const PI_2 = PI / 2.0 const PI_2 = PI / 2.0
var debug:bool = false const JUMP_FORCE = 4.5
var reconciliate_rotate_camer_player:bool = true
# Get the gravity from the project settings to be synced with RigidDynamicBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
var starting_point = Vector2(DisplayServer.window_get_size().x / 2, DisplayServer.window_get_size().y / 2)
# Camera position
var camera_rotate_y = 0.0
var camera_rotate_x = 0.0
# Player position
var player_rotate_y = 0.0
#var debug:bool = false
# Activate reconciliation between camera & player
var reconciliate_rotate_camera_player:bool = true
var is_run:bool = false var is_run:bool = false
# var speed = SPEED_WALK
func _init(): func _init():
@ -54,21 +50,21 @@ func _input(event):
# If right mouse button is pressed and mouse moves, pan horizontally camera # If right mouse button is pressed and mouse moves, pan horizontally camera
# and rotate vertically # and rotate vertically
if Input.is_action_just_pressed ( "ui_strafe" ): if Input.is_action_just_pressed ( "ui_strafe" ):
reconciliate_rotate_camer_player = false reconciliate_rotate_camera_player = false
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
elif Input.is_action_just_released ( "ui_strafe" ): elif Input.is_action_just_released ( "ui_strafe" ):
reconciliate_rotate_camer_player = true reconciliate_rotate_camera_player = true
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.is_action_just_pressed( "move_run" ): if Input.is_action_just_pressed( "move_run" ):
is_run = true is_run = true
elif Input.is_action_just_released( "move_run" ): elif Input.is_action_just_released( "move_run" ):
is_run = false is_run = false
if Input.is_action_just_released("ui_cut"): # if Input.is_action_just_released("ui_cut"):
print("debug on") # print("debug on")
debug = true # debug = true
if Input.is_action_just_released("ui_copy"): # if Input.is_action_just_released("ui_copy"):
print("debug off") # print("debug off")
debug = false # debug = false
if Input.is_mouse_button_pressed( 2 ): if Input.is_mouse_button_pressed( 2 ):
if event is InputEventMouseMotion: if event is InputEventMouseMotion:
@ -99,23 +95,16 @@ func _physics_process(delta):
motion_velocity.y -= gravity * delta motion_velocity.y -= gravity * delta
# Handle Jump. # Handle Jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor(): # if Input.is_action_just_pressed("ui_accept") and is_on_floor():
motion_velocity.y = JUMP_FORCE # motion_velocity.y = JUMP_FORCE
#
# if is_run:
# speed = SPEED_RUN
# else:
# speed = SPEED_WALK
# Get the input direction and handle the movement/deceleration. # Get the input direction and handle the movement/deceleration.
if Input.is_action_pressed("ui_strafe"): if Input.is_action_pressed("ui_strafe"):
if Input.is_action_pressed("ui_left"): if Input.is_action_pressed("ui_left"):
input_x = 1.0 input_x = 1.0
# speed *= MUL_SPEED_STRAFE
move_strafe = true move_strafe = true
elif Input.is_action_pressed("ui_right"): elif Input.is_action_pressed("ui_right"):
input_x = -1.0 input_x = -1.0
# speed *= MUL_SPEED_STRAFE
move_strafe = true move_strafe = true
else: else:
var y = 0 var y = 0
@ -139,7 +128,6 @@ func _physics_process(delta):
elif Input.is_action_pressed("ui_down"): elif Input.is_action_pressed("ui_down"):
input_y = -1.0 input_y = -1.0
move_down = true move_down = true
# speed *= MUL_SPEED_DOWN
if is_run: if is_run:
if move_strafe: if move_strafe:
@ -166,8 +154,6 @@ func _physics_process(delta):
else: else:
speed = SPEED_WALK_DOWN speed = SPEED_WALK_DOWN
print(speed)
var direction = (transform.basis * Vector3(input_x, 0, input_y)).normalized() var direction = (transform.basis * Vector3(input_x, 0, input_y)).normalized()
if direction: if direction:
motion_velocity.x = direction.x * speed motion_velocity.x = direction.x * speed
@ -180,10 +166,10 @@ func _physics_process(delta):
func _process( delta ): func _process( delta ):
if debug: # if debug:
print(reconciliate_rotate_camer_player, ", ", camera_rotate_y,", ", player_rotate_y) # print(reconciliate_rotate_camera_player, ", ", camera_rotate_y,", ", player_rotate_y)
if reconciliate_rotate_camer_player: if reconciliate_rotate_camera_player:
var diff = camera_rotate_y - player_rotate_y var diff = camera_rotate_y - player_rotate_y
if diff > PI: if diff > PI:

View file

@ -52,6 +52,16 @@ ui_strafe={
} }
move_run={ move_run={
"deadzone": 0.5, "deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":0,"physical_keycode":16777237,"unicode":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":16777237,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
]
}
camera_zoom_in={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":4,"pressed":false,"double_click":false,"script":null)
]
}
camera_zoom_out={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":5,"pressed":false,"double_click":false,"script":null)
] ]
} }