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"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_568l5"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_kcbxg"]
[node name="Player" type="RigidBody3D"]
lock_rotation = true
linear_damp = 3.0
[node name="Player" type="CharacterBody3D"]
script = ExtResource("1_ady3x")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("CapsuleShape3D_568l5")
shape = SubResource("CapsuleShape3D_kcbxg")
[node name="Head" type="Node3D" parent="."]
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")
[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)
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")

View file

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