Anri/AdBlockNot
Archived
1
0
Fork 0

Change player from RigidBody3D to CharacterBody3D

This commit is contained in:
Mylloon 2024-01-27 13:36:33 +01:00
parent 4181a18804
commit a79b24d625
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 21 additions and 19 deletions

View file

@ -2,15 +2,13 @@
[ext_resource type="Script" path="res://scripts/Player.gd" id="1_ady3x"] [ext_resource type="Script" path="res://scripts/Player.gd" id="1_ady3x"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_568l5"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_kcbxg"]
[node name="Player" type="RigidBody3D"] [node name="Player" type="CharacterBody3D"]
lock_rotation = true
linear_damp = 3.0
script = ExtResource("1_ady3x") script = ExtResource("1_ady3x")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("CapsuleShape3D_568l5") shape = SubResource("CapsuleShape3D_kcbxg")
[node name="Head" type="Node3D" parent="."] [node name="Head" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.8, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.8, 0)

View file

@ -43,13 +43,13 @@ mesh = SubResource("PlaneMesh_vfc5y")
shape = SubResource("ConcavePolygonShape3D_ibbj3") shape = SubResource("ConcavePolygonShape3D_ibbj3")
[node name="Player" parent="." instance=ExtResource("1_r5ocp")] [node name="Player" parent="." instance=ExtResource("1_r5ocp")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.1, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
[node name="Bureau3" type="MeshInstance3D" parent="."] [node name="Bureau" type="MeshInstance3D" parent="."]
transform = Transform3D(0.015, 0, 0, 0, 0.015, 0, 0, 0, 0.015, 0.145715, 0.531814, -3.61084) transform = Transform3D(0.015, 0, 0, 0, 0.015, 0, 0, 0, 0.015, 0.145715, 0.531814, -3.61084)
mesh = ExtResource("2_b86p5") mesh = ExtResource("2_b86p5")
[node name="StaticBody3D" type="StaticBody3D" parent="Bureau3"] [node name="StaticBody3D" type="StaticBody3D" parent="Bureau"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Bureau3/StaticBody3D"] [node name="CollisionShape3D" type="CollisionShape3D" parent="Bureau/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_m6gwj") shape = SubResource("ConcavePolygonShape3D_m6gwj")

View file

@ -1,13 +1,13 @@
extends RigidBody3D extends CharacterBody3D
@onready var head := $Head @onready var head := $Head
const SPEED := 1200.0 const SPEED := 5.0
const MOUSE_SENSITIVITY := 0.15 const MOUSE_SENSITIVITY := 0.15
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
# Change input mode # Trap the cursor on start
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
# Called at each input # Called at each input
@ -21,13 +21,17 @@ func _input(event):
# Trap the cursor on click # Trap the cursor on click
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
# Called every frame. 'delta' is the elapsed time since the previous frame. func _physics_process(delta):
func _process(delta): # Get the input direction and handle the movement/deceleration.
# Movement var input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
var input := Vector3.ZERO var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
input.x = Input.get_axis("move_left", "move_right") if direction:
input.z = Input.get_axis("move_forward", "move_backward") velocity.x = direction.x * SPEED
apply_central_force(basis * input.normalized() * SPEED * delta) velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()
# Free cursor # Free cursor
if Input.is_action_just_pressed("ui_cancel"): if Input.is_action_just_pressed("ui_cancel"):