adding keyboard move, switch mouse rotation

This commit is contained in:
AleaJactaEst 2022-02-03 12:55:05 +01:00
parent 4a6692050c
commit 553741deef
3 changed files with 115 additions and 148 deletions

View file

@ -5,84 +5,66 @@
[node name="character" instance=ExtResource( "1_2jxjm" )]
[node name="Skeleton3D" parent="char_grp/rig" index="0"]
bones/2/position = Vector3(-0.0137206, -0.00893447, 0.623635)
bones/2/rotation = Quaternion(-0.0542181, -0.698824, 0.705138, 0.107172)
bones/5/position = Vector3(0.225526, -0.0449977, 1.00549)
bones/5/rotation = Quaternion(-0.212256, 0.507514, -0.409583, 0.727749)
bones/6/rotation = Quaternion(0.0763622, -0.151315, 0.201611, 0.964689)
bones/9/rotation = Quaternion(-0.354247, -0.0113183, -0.114535, 0.928042)
bones/12/rotation = Quaternion(-0.0859619, -0.000690616, -0.0113947, 0.996233)
bones/14/rotation = Quaternion(-0.0708235, 0.00135137, 0.00912021, 0.997446)
bones/17/rotation = Quaternion(-0.289619, 0.0147139, -0.0606385, 0.955105)
bones/20/rotation = Quaternion(-0.071225, -0.000127472, -0.014186, 0.997359)
bones/22/rotation = Quaternion(-0.050349, -0.000215399, -0.00607436, 0.998713)
bones/25/rotation = Quaternion(-0.189839, 0.0091794, -0.0234996, 0.98149)
bones/28/rotation = Quaternion(-0.0475135, 0.000428396, -0.011606, 0.998803)
bones/30/rotation = Quaternion(-0.0834221, 0.000160671, 0.00221177, 0.996512)
bones/33/rotation = Quaternion(-0.396376, -0.000130737, -0.142626, 0.906942)
bones/36/rotation = Quaternion(-0.172635, 0.0012423, -0.0155044, 0.984863)
bones/38/rotation = Quaternion(-0.0638606, 0.00298732, 0.0124317, 0.997877)
bones/41/rotation = Quaternion(-0.033223, -0.0646825, 0.00673106, 0.99733)
bones/44/rotation = Quaternion(-0.170821, 0.00587304, -0.0810434, 0.981944)
bones/46/rotation = Quaternion(-0.120295, 0.00125632, 0.0085031, 0.9927)
bones/47/position = Vector3(-0.134833, 0.0653124, 1.13379)
bones/47/rotation = Quaternion(-0.659221, -0.0283842, 0.430366, 0.61596)
bones/50/position = Vector3(-0.19488, 0.0360943, 1.03029)
bones/50/rotation = Quaternion(-0.632594, -0.189283, 0.26349, 0.703257)
bones/53/rotation = Quaternion(1.23425e-07, 0.194622, 2.8287e-07, 0.980878)
bones/55/position = Vector3(0.225526, -0.0449977, 1.00549)
bones/55/rotation = Quaternion(-0.212256, 0.507514, -0.409583, 0.727749)
bones/56/rotation = Quaternion(-2.54969e-07, -0.158062, -1.24093e-07, 0.987429)
bones/60/position = Vector3(-0.0306801, -0.00903376, 0.410954)
bones/60/rotation = Quaternion(0.27466, -0.583274, 0.654977, 0.394154)
bones/61/rotation = Quaternion(-1.67814e-07, 0.00969424, -2.09387e-07, 0.999953)
bones/65/position = Vector3(0.228274, 0.0354965, 0.486375)
bones/65/rotation = Quaternion(-0.736181, -0.0420695, 0.0630477, 0.672527)
bones/66/rotation = Quaternion(-3.45758e-08, -0.0658087, -1.18379e-08, 0.997832)
bones/70/position = Vector3(-0.19488, 0.0360944, 1.03029)
bones/70/rotation = Quaternion(-0.632594, -0.189283, 0.263491, 0.703256)
bones/71/rotation = Quaternion(-0.133067, 0.197528, 0.0747902, 0.96834)
bones/74/rotation = Quaternion(-0.274108, 0.0121625, 0.120633, 0.954025)
bones/77/rotation = Quaternion(-0.151302, 0.00120142, 0.0177719, 0.988327)
bones/79/rotation = Quaternion(-0.115412, 0.00165681, 0.0111454, 0.993254)
bones/82/rotation = Quaternion(-0.179167, -0.00608298, 0.0625111, 0.981812)
bones/85/rotation = Quaternion(-0.126398, 1.04667e-05, 0.019615, 0.991786)
bones/87/rotation = Quaternion(-0.0748097, 0.000649867, 0.00982608, 0.997149)
bones/90/rotation = Quaternion(-0.0496308, 0.0679533, -0.0180453, 0.99629)
bones/93/rotation = Quaternion(-0.123578, 0.0137458, 0.101123, 0.987073)
bones/95/rotation = Quaternion(-0.118975, 6.71328e-05, -0.000388975, 0.992897)
bones/98/rotation = Quaternion(-0.0805458, -0.000323918, 0.0182939, 0.996583)
bones/101/rotation = Quaternion(-0.0693506, -0.00070072, 0.013769, 0.997497)
bones/103/rotation = Quaternion(-0.0785608, 0.00150039, 0.00594976, 0.99689)
bones/106/rotation = Quaternion(-0.328283, 0.00323289, 0.147203, 0.933033)
bones/109/rotation = Quaternion(-0.210199, -0.0015143, 0.0192418, 0.977468)
bones/111/rotation = Quaternion(-0.088144, 0.0013427, 0.0161606, 0.995976)
bones/112/position = Vector3(0.019602, 0.0386716, 0.866973)
bones/112/rotation = Quaternion(0.532326, 0.514181, 0.504871, 0.444244)
bones/113/rotation = Quaternion(-0.0649652, 0.110191, -0.0360143, 0.991131)
bones/116/rotation = Quaternion(0.0561334, 0.300638, -0.0189887, 0.951895)
bones/120/rotation = Quaternion(0.148044, 0.0480133, -0.00268973, 0.98781)
bones/123/rotation = Quaternion(-0.508658, 0.40436, 0.59608, 0.471645)
bones/125/rotation = Quaternion(-0.428569, -0.0251431, 0.238236, 0.871172)
bones/129/rotation = Quaternion(-0.601724, -0.289307, -0.457284, 0.587471)
bones/131/rotation = Quaternion(-0.488059, 0.108326, 0.00490083, 0.866049)
bones/139/rotation = Quaternion(-0.135171, -0.00136852, -0.227491, 0.964352)
bones/140/rotation = Quaternion(0.0537204, -0.042591, 0.290175, 0.954515)
bones/142/rotation = Quaternion(0.483791, 0.550795, -0.400661, 0.549583)
bones/143/rotation = Quaternion(0.00484993, 0.9864, 0.164286, 0.00110764)
bones/144/rotation = Quaternion(-0.13481, -4.23659e-08, -0.227675, 0.96436)
bones/148/rotation = Quaternion(0.0382164, -2.35926e-08, -0.0828285, 0.995831)
bones/151/rotation = Quaternion(0.0457827, 0.0887355, -0.0791179, 0.991852)
bones/152/rotation = Quaternion(0.0968234, -0.0159964, -0.430017, 0.897471)
bones/154/rotation = Quaternion(0.313121, -0.578061, 0.414367, 0.629366)
bones/155/rotation = Quaternion(-0.00376207, 0.973964, 0.226656, 0.00254173)
bones/156/position = Vector3(0.183474, -0.0360153, 1.116)
bones/156/rotation = Quaternion(-0.366684, 0.410974, -0.627613, 0.550222)
bones/159/position = Vector3(0.113059, 0.0613343, 0.667578)
bones/159/rotation = Quaternion(-0.729315, -0.228512, -0.168593, 0.622461)
bones/162/position = Vector3(0.040388, 0.0554522, 1.35329)
bones/162/rotation = Quaternion(0.230239, 0.730674, 0.611786, 0.197031)
bones/163/rotation = Quaternion(-0.102034, 0.307882, -0.036231, 0.945242)
bones/2/rotation = Quaternion(-0.271757, 0.626496, -0.507842, 0.525117)
bones/5/rotation = Quaternion(-0.445372, 0.390831, -0.410612, 0.693032)
bones/6/rotation = Quaternion(-0.0372555, -0.0374979, 0.122351, 0.991078)
bones/9/rotation = Quaternion(-0.55327, -0.021387, -0.0662289, 0.830089)
bones/12/rotation = Quaternion(-0.69924, -0.00070756, -0.0840618, 0.709928)
bones/14/rotation = Quaternion(-0.281124, -0.000329497, -0.0339629, 0.95907)
bones/17/rotation = Quaternion(-0.541706, 0.00703882, -0.0505262, 0.839019)
bones/20/rotation = Quaternion(-0.727666, -0.00506352, -0.0876433, 0.680291)
bones/22/rotation = Quaternion(-0.340549, -0.00194646, -0.041411, 0.939312)
bones/25/rotation = Quaternion(-0.55521, 0.0120764, -0.0438172, 0.830467)
bones/28/rotation = Quaternion(-0.864959, 0.00479228, -0.103815, 0.490964)
bones/30/rotation = Quaternion(-0.171698, -0.00446994, -0.0205173, 0.984926)
bones/38/rotation = Quaternion(-0.38892, -0.00569116, -0.0466897, 0.92007)
bones/41/rotation = Quaternion(0.0189979, 0.0622678, -0.039629, 0.997091)
bones/44/rotation = Quaternion(-0.352984, -0.0533485, -0.00972458, 0.934057)
bones/47/rotation = Quaternion(-0.491492, -0.286184, 0.496952, 0.655418)
bones/50/rotation = Quaternion(-0.440024, -0.360322, 0.385434, 0.726628)
bones/53/rotation = Quaternion(1.24162e-07, -0.0289177, 2.77174e-07, 0.999582)
bones/55/rotation = Quaternion(-0.445372, 0.390831, -0.410612, 0.693032)
bones/56/rotation = Quaternion(-2.72248e-07, -0.040541, -1.08628e-07, 0.999178)
bones/60/rotation = Quaternion(-0.502103, 0.436597, -0.652123, 0.363333)
bones/65/rotation = Quaternion(-0.519517, -0.442971, 0.636258, 0.359241)
bones/66/rotation = Quaternion(9.07769e-10, 0.0551515, 3.5838e-08, 0.998478)
bones/70/rotation = Quaternion(-0.440024, -0.360322, 0.385434, 0.726628)
bones/71/rotation = Quaternion(-0.067789, -0.0294414, -0.0321137, 0.996748)
bones/74/rotation = Quaternion(-0.529658, 0.0176954, 0.0583603, 0.846016)
bones/77/rotation = Quaternion(-0.686348, 0.000695412, 0.0817067, 0.722669)
bones/79/rotation = Quaternion(-0.325638, 0.000781165, 0.0388156, 0.944697)
bones/82/rotation = Quaternion(-0.508272, -0.0129833, 0.0348485, 0.860393)
bones/85/rotation = Quaternion(-0.788088, 0.00548676, 0.0939959, 0.608319)
bones/90/rotation = Quaternion(0.0583021, -0.0664381, 0.18425, 0.978897)
bones/93/rotation = Quaternion(-0.325608, 0.00672599, -0.0201309, 0.945267)
bones/95/rotation = Quaternion(-0.476819, 0.0786276, -0.0477728, 0.874173)
bones/98/rotation = Quaternion(-0.474577, -0.0113585, 0.0306311, 0.879608)
bones/101/rotation = Quaternion(-0.781749, -0.0043309, 0.0929099, 0.616618)
bones/103/rotation = Quaternion(-0.357714, 0.00928428, 0.0423253, 0.932826)
bones/106/rotation = Quaternion(-0.574211, 0.0203224, 0.0987876, 0.812471)
bones/109/rotation = Quaternion(-0.663777, 0.0235976, 0.0521688, 0.745736)
bones/111/rotation = Quaternion(-0.361751, 0.00527712, 0.0430036, 0.931268)
bones/112/rotation = Quaternion(0.0097308, -0.701742, -0.712346, 0.00508848)
bones/113/rotation = Quaternion(-0.0911941, -0.00258285, 0.000984978, 0.995829)
bones/116/rotation = Quaternion(0.080616, 0.00590208, 0.00270844, 0.996724)
bones/120/rotation = Quaternion(0.105174, 0.00605958, 0.0129845, 0.994351)
bones/123/rotation = Quaternion(-0.562449, 0.324106, 0.455498, 0.609203)
bones/125/rotation = Quaternion(-0.539888, -0.0493987, 0.199217, 0.816329)
bones/129/rotation = Quaternion(-0.558722, -0.301251, -0.453266, 0.625802)
bones/131/rotation = Quaternion(-0.508332, 0.0333607, -0.240729, 0.826157)
bones/139/rotation = Quaternion(0.0980113, -0.0899481, -0.0867249, 0.98731)
bones/140/rotation = Quaternion(-0.0310007, 0.0719017, 0.355743, 0.931298)
bones/142/rotation = Quaternion(0.470828, 0.517658, -0.563252, 0.439429)
bones/143/rotation = Quaternion(0.00477369, 0.990276, 0.139034, 0.000545654)
bones/144/rotation = Quaternion(0.105475, -3.99246e-08, -0.0774747, 0.991399)
bones/148/rotation = Quaternion(0.0834681, -3.02306e-08, 0.0769496, 0.993535)
bones/151/rotation = Quaternion(0.0726204, 0.130697, 0.0872612, 0.984901)
bones/152/rotation = Quaternion(0.0219061, -0.0761316, -0.353842, 0.931944)
bones/154/rotation = Quaternion(0.474683, -0.474536, 0.557822, 0.488187)
bones/155/rotation = Quaternion(0.0047883, -0.989589, -0.143844, 0.0006509)
bones/156/rotation = Quaternion(-0.492611, 0.329333, -0.498554, 0.632707)
bones/162/rotation = Quaternion(0.000208666, -0.699219, -0.714693, 0.0175177)
bones/163/rotation = Quaternion(-0.0303771, 0.00768932, 0.00157884, 0.999508)
[node name="AnimationPlayer" parent="." index="1"]
autoplay = "CHAR_idle_bored"

View file

@ -9,7 +9,6 @@ var starting_point = Vector2(DisplayServer.window_get_size().x / 2, DisplayServe
var camera_rotate_y = 0.0
var camera_rotate_x = 0.0
var player_rotate_y = 0.0
#var timer_rotate:Timer
var speed_rotate_1sec = PI
var max_angle = PI / 2
const TWO_PI = 2.0 * PI
@ -17,11 +16,6 @@ const PI_2 = PI / 2.0
func _init():
# timer_rotate = Timer.new()
# add_child(timer_rotate)
# timer_rotate.autostart = false
# timer_rotate.wait_time = 1.0
# timer_rotate.connect("timeout", update_rotate_start.bind())
pass
@ -33,38 +27,24 @@ func _ready():
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" ):
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
elif Input.is_action_just_released ( "ui_strafe" ):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.is_mouse_button_pressed( 2 ):
if event is InputEventMouseMotion:
camera_rotate_y += event.relative.x *0.01
camera_rotate_y -= event.relative.x *0.01
if camera_rotate_y >= PI:
camera_rotate_y -= TWO_PI
elif camera_rotate_y <= -PI:
camera_rotate_y += TWO_PI
$camera_root/horizontal_root.rotate_y( event.relative.x *0.01 )
$camera_root/horizontal_root.rotate_y( -event.relative.x *0.01 )
# if (roty >= 0.0 and max_angle > roty) or (roty <= 0.0 and max_angle > -roty):
# $camera_root/horizontal_root.rotate_y( event.relative.x *0.01 )
# camera_rotate = roty
# else:
# $Mesh/character.rotate_y( event.relative.x *0.01 )
# $camera_root/horizontal_root.rotate_y( event.relative.x *0.01 )
var new_camera_rotate_x = camera_rotate_x + event.relative.y * 0.01
if new_camera_rotate_x <= PI_2 and new_camera_rotate_x >= - PI_2:
$camera_root/horizontal_root/vertical_root.rotate_x( event.relative.y * 0.01 )
camera_rotate_x = new_camera_rotate_x
# timer_rotate.autostart = false
# timer_rotate.wait_time = 1.0
# if timer_rotate.is_connected("timeout", update_rotate.bind()):
# timer_rotate.stop()
# timer_rotate.disconnect("timeout", update_rotate.bind())
# timer_rotate.connect("timeout", update_rotate_start.bind())
# timer_rotate.start(1.0)
# print("Update timer")
# else:
# #timer_rotate.stop()
# timer_rotate.start(1.0)
# print("launch timer")
func _physics_process(delta):
@ -76,16 +56,33 @@ func _physics_process(delta):
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.
# # As good practice, you should replace UI actions with custom gameplay actions.
# var input_dir = Input.get_vector("ui_right", "ui_left", "ui_down", "ui_up")
# var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
# if direction:
# motion_velocity.x = direction.x * SPEED
# motion_velocity.z = direction.z * SPEED
# else:
# motion_velocity.x = move_toward(motion_velocity.x, 0, SPEED)
# motion_velocity.z = move_toward(motion_velocity.z, 0, SPEED)
if not Input.is_action_pressed( "ui_strafe" ):
var y = 0
if Input.is_action_pressed("ui_right"):
y -= 1
if Input.is_action_pressed("ui_left"):
y += 1
if y != 0:
var dt = y * delta * speed_rotate_1sec
camera_rotate_y += dt
if camera_rotate_y >= PI:
camera_rotate_y -= TWO_PI
elif camera_rotate_y <= -PI:
camera_rotate_y += TWO_PI
$camera_root/horizontal_root.rotate_y( dt )
# 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_strafe_right", "ui_strafe_left", "ui_down", "ui_up")
if Input.is_action_pressed("ui_strafe"):
input_dir = Input.get_vector("ui_right", "ui_left", "ui_down", "ui_up")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
motion_velocity.x = direction.x * SPEED
motion_velocity.z = direction.z * SPEED
else:
motion_velocity.x = move_toward(motion_velocity.x, 0, SPEED)
motion_velocity.z = move_toward(motion_velocity.z, 0, SPEED)
move_and_slide()
@ -102,43 +99,16 @@ func _process( delta ):
absdiff = -absdiff
if absdiff <= 0.5 * delta:
$Mesh/character.rotate_y( diff )
rotate_y( diff )
$camera_root/horizontal_root.rotate_y( -diff )
# $Mesh/character.rotate_y( diff )
player_rotate_y = camera_rotate_y
else:
if diff >= 0.0:
diff = delta * speed_rotate_1sec
else:
diff = -delta * speed_rotate_1sec
$Mesh/character.rotate_y( diff )
rotate_y( diff )
$camera_root/horizontal_root.rotate_y( -diff )
#$Mesh/character.rotate_y( diff )
player_rotate_y += diff
#func update_rotate_start():
# print("update_rotate_start")
# var camera = $camera_root/horizontal_root.get_basis()
# var player = $Mesh/character.get_basis()
# timer_rotate.disconnect("timeout", update_rotate_start.bind())
# timer_rotate.connect("timeout", update_rotate.bind())
# timer_rotate.start(0.005)
#
#
#func update_rotate():
# print("update_rotate")
# var step = 0.0
# if camera_rotate >= 0.1:
# step = -0.05
# elif camera_rotate <= -0.1:
# step = +0.05
# $Mesh/character.rotate_y( -step )
# #$camera_root/horizontal_root.rotate_y( step / 2.0 )
# camera_rotate += step
## if (roty >= 0.0 and max_angle > roty) or (roty <= 0.0 and max_angle > -roty):
## $camera_root/horizontal_root.rotate_y( event.relative.x *0.01 )
## current_rotate = roty
## else:
## $Mesh/character.rotate_y( event.relative.x *0.01 )
## $camera_root/horizontal_root.rotate_y( event.relative.x *0.01 )
# if camera_rotate <= 0.1 and camera_rotate >= -0.1:
# timer_rotate.stop()

View file

@ -45,3 +45,18 @@ ui_down={
, 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":83,"unicode":0,"echo":false,"script":null)
]
}
ui_strafe_left={
"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":true,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"unicode":0,"echo":false,"script":null)
]
}
ui_strafe_right={
"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":true,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"unicode":0,"echo":false,"script":null)
]
}
ui_strafe={
"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":1,"pressed":false,"double_click":false,"script":null)
]
}