#Try to move my player

11 messages · Page 1 of 1 (latest)

dawn osprey
#

No matter I pressing W to forward, this still not moving. I dont know whats went wrong with it.

rugged bough
#

Check the input, I think there is an error ...

ornate badge
#

On line 22, the function Input.get_vector() takes four strings, "ui_up", "ui_down", etc. These correspond to the names of the actions in the input map. So for your project, you should change the "ui_up" to "forward" and then add the other actions for the other directions.

dawn osprey
#

Yes, I did that. Now its rotating my player.

rugged bough
#

Your cam is rotating, not the player, very good ... gdthumbsup

dawn osprey
dreamy junco
dawn osprey
# dreamy junco instead of changing the camera's rotation, change the player rotation instead wi...

I followed this tutorial.
https://www.youtube.com/watch?v=RV-Nwy8N68o

Where I put them in Gscript?


func _input(event):
if event is InputEventMouseMotion:
look_rot.y -= (event.relative.x * sensitivity)
look_rot.x -= (event.relative.y * sensitivity)
look_rot.x = clamp(look_rot.x, min_angle, max_angle)

Learn how to create a basic FPS controller with crouching (Yeah I forgot about it last time lol) in Godot 4.

•Links:
Link to the project:
https://github.com/nagidev/godot-tutorials/tree/godot-4-basic-fps

If you have questions, comment them down below.
If you enjoyed the video, drink apple juice.

Do you want to support my content?
https://ko-f...

▶ Play video
dreamy junco
dawn osprey
# dreamy junco Can you show the full code for the rotation?

extends CharacterBody3D

@export var speed = 8.0
@export var crouch_speed = 4.0
@export var accel = 16.0
@export var jump = 8.0
@export var crouch_height = 2.4
@export var crouch_transition = 8.0
@export var sensitivity = 0.2
@export var min_angle = -80
@export var max_angle = 90

@onready var Camerapivot = $Camerapivot
@onready var collision_shape = $CollisionShape3D
@onready var top_cast = $TopCast

var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
var look_rot : Vector2
var stand_height : float

func _ready():
stand_height = collision_shape.shape.height
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _physics_process(delta):
var move_speed = speed

if not is_on_floor():
    velocity.y -= gravity * delta
else:
    if Input.is_action_just_pressed("jump"):
        velocity.y = jump
    elif Input.is_action_pressed("crouch") or top_cast.is_colliding():
        move_speed = crouch_speed
        crouch(delta)
    else:
        crouch(delta, true)

var input_dir = Input.get_vector("left", "right", "backward", "forward")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
    velocity.x = lerp(velocity.x, direction.x * move_speed, accel * delta)
    velocity.z = lerp(velocity.z, direction.z * move_speed, accel * delta)
else:
    velocity.x = lerp(velocity.x, 0.0, accel * delta)
    velocity.z = lerp(velocity.z, 0.0, accel * delta)

move_and_slide()

var plat_rot = get_platform_angular_velocity()
look_rot.y += rad_to_deg(plat_rot.y * delta)
Camerapivot.rotation_degrees.x = look_rot.x
rotation_degrees.y = look_rot.y

func _input(event):
if event is InputEventMouseMotion:
look_rot.y -= (event.relative.x * sensitivity)
look_rot.x -= (event.relative.y * sensitivity)
look_rot.x = clamp(look_rot.x, min_angle, max_angle)