clean code, disable jump, disable debug message
This commit is contained in:
parent
e398c8d8e1
commit
318fec80ee
2 changed files with 38 additions and 42 deletions
|
@ -6,16 +6,7 @@ extends CharacterBody3D
|
|||
# |
|
||||
# Down
|
||||
|
||||
#const SPEED = 5.0
|
||||
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
|
||||
|
||||
# Constant
|
||||
const SPEED_WALK_UP = 5.0
|
||||
const SPEED_WALK_UP_STRAFE = 3.0
|
||||
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 = 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 PI_2 = PI / 2.0
|
||||
var debug:bool = false
|
||||
var reconciliate_rotate_camer_player:bool = true
|
||||
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)
|
||||
# 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 speed = SPEED_WALK
|
||||
|
||||
|
||||
func _init():
|
||||
|
@ -54,21 +50,21 @@ func _input(event):
|
|||
# If right mouse button is pressed and mouse moves, pan horizontally camera
|
||||
# and rotate vertically
|
||||
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)
|
||||
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)
|
||||
if Input.is_action_just_pressed( "move_run" ):
|
||||
is_run = true
|
||||
elif Input.is_action_just_released( "move_run" ):
|
||||
is_run = false
|
||||
if Input.is_action_just_released("ui_cut"):
|
||||
print("debug on")
|
||||
debug = true
|
||||
if Input.is_action_just_released("ui_copy"):
|
||||
print("debug off")
|
||||
debug = false
|
||||
# if Input.is_action_just_released("ui_cut"):
|
||||
# print("debug on")
|
||||
# debug = true
|
||||
# if Input.is_action_just_released("ui_copy"):
|
||||
# print("debug off")
|
||||
# debug = false
|
||||
|
||||
if Input.is_mouse_button_pressed( 2 ):
|
||||
if event is InputEventMouseMotion:
|
||||
|
@ -99,23 +95,16 @@ func _physics_process(delta):
|
|||
motion_velocity.y -= gravity * delta
|
||||
|
||||
# Handle Jump.
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
motion_velocity.y = JUMP_FORCE
|
||||
#
|
||||
# if is_run:
|
||||
# speed = SPEED_RUN
|
||||
# else:
|
||||
# speed = SPEED_WALK
|
||||
# if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
# motion_velocity.y = JUMP_FORCE
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
if Input.is_action_pressed("ui_strafe"):
|
||||
if Input.is_action_pressed("ui_left"):
|
||||
input_x = 1.0
|
||||
# speed *= MUL_SPEED_STRAFE
|
||||
move_strafe = true
|
||||
elif Input.is_action_pressed("ui_right"):
|
||||
input_x = -1.0
|
||||
# speed *= MUL_SPEED_STRAFE
|
||||
move_strafe = true
|
||||
else:
|
||||
var y = 0
|
||||
|
@ -139,7 +128,6 @@ func _physics_process(delta):
|
|||
elif Input.is_action_pressed("ui_down"):
|
||||
input_y = -1.0
|
||||
move_down = true
|
||||
# speed *= MUL_SPEED_DOWN
|
||||
|
||||
if is_run:
|
||||
if move_strafe:
|
||||
|
@ -166,8 +154,6 @@ func _physics_process(delta):
|
|||
else:
|
||||
speed = SPEED_WALK_DOWN
|
||||
|
||||
print(speed)
|
||||
|
||||
var direction = (transform.basis * Vector3(input_x, 0, input_y)).normalized()
|
||||
if direction:
|
||||
motion_velocity.x = direction.x * speed
|
||||
|
@ -180,10 +166,10 @@ func _physics_process(delta):
|
|||
|
||||
|
||||
func _process( delta ):
|
||||
if debug:
|
||||
print(reconciliate_rotate_camer_player, ", ", camera_rotate_y,", ", player_rotate_y)
|
||||
# if debug:
|
||||
# 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
|
||||
|
||||
if diff > PI:
|
||||
|
|
|
@ -52,6 +52,16 @@ ui_strafe={
|
|||
}
|
||||
move_run={
|
||||
"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)
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue