Skip to content

Commit

Permalink
joystick movement
Browse files Browse the repository at this point in the history
  • Loading branch information
janekx21 committed Jul 3, 2023
1 parent 72eaa50 commit 9d079c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions code/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ extends CharacterBody3D

func _physics_process(delta: float) -> void:
var move = get_move()
#var planar = Vector3(move.x, 0, -move.y)
var move_target = move * max_speed
var move_delta = delta * acceleration

Expand All @@ -14,13 +13,21 @@ func _physics_process(delta: float) -> void:
velocity.x = planar_velocity.x
velocity.z = planar_velocity.y
velocity.y -= delta * 50


move_and_slide()


func get_move() -> Vector2:
var x = Input.get_axis("move_left", "move_right")
x += Input.get_joy_axis(0, JOY_AXIS_LEFT_X)
var y = Input.get_axis("move_up", "move_down")
return Vector2(x,y).normalized()
y += Input.get_joy_axis(0, JOY_AXIS_LEFT_Y)
var dir = Vector2(x,y)
if dir.length() > 1:
return dir.normalized()
else:
return dir

func extend(value: Vector2, with: float) -> Vector3:
return Vector3(value.x, value.y, with)
Expand Down
1 change: 1 addition & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ move_down={
attack={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":false,"script":null)
]
}

Expand Down

0 comments on commit 9d079c8

Please sign in to comment.