Why cant I move the player?

Godot Version

Godot 4.2


I’ve followed exact instructions from Godot 101 Tutortial and made 3 player scripts to move my character even IKskeleton or CharaterBody3D, however, none of them move it.

I did root it:
I->Player with Gscript
I–>Camera Pivot
I–> Camera3D

Its still not moving. I input WASD to Input Map and got the same result.

Here’s the Gscript


extends CharacterBody3D

var gravity = Vector3.DOWN * 12
var speed = 4
var jump_speed = 6

var velocity = Vector3()

func _physics_process(delta):
velocity += gravity * delta
velocity = move_and_slide(velocity, Vector3.UP)

func get_input():
velocity.x = 0
velocity.z = 0
if Input.is_action_pressed(“move_forward”):
velocity.z -= speed
if Input.is_action_pressed(“move_back”):
velocity.z += speed
if Input.is_action_pressed(“strafe_right”):
velocity.x += speed
if Input.is_action_pressed(“move_left”):
velocity.x -= speed

/ Blockquote

I’ve been struggling with this for 2 days, researched the tutorial, and talked with users in Godot Discord. None of them are worked!
I wanted to post the video here, but Im new Godot isn’t allowed to post any image or video.

The best thing to do would be to use the standard script for a 3d controller.
What you would do is create a new character body 3d, then create a script, and make sure it has the controller template, like so:

You can move the player with the standard arrow keys, and you can use custom actions if you want WASD.
You’ll have to set up the camera system and anything else yourself, or with another tutorial.

As a follow-up, the tutorial you are using was made for godot 3, not godot 4.

1 Like

As mmull said that video is for GODOT 3.x.
You must have already realized that when instead of a KinematicBody you used the 4.x exclusive CharacterBody.

The CharacterBody contains a member velocity so you don’t create one in your script.
Add to that the fact that move_and_slide() no longer take parameters and no longer returns a vector. It now returns a bool.

I have been looking at a few 3d controller videos. Try this one.

When posting code you use the </> menu item to post it properly formatted.

As mmull said that video is for GODOT 3.x.
You must have already realized that when instead of a KinematicBody you used the 4.x exclusive CharacterBody.

Isn’t KinematicBody renamed to CharacterBody3D?
I’ve watched and followed instructions from your link halfway and my player didn’t respond to jump the way Polyglot Programmer did at 14:05

Edited: Scratch that. I put player on the ground then pressed Space to jump and it did.

So I don’t need to put either of velocity and move_and_slide() in the Gscript even Polyglot wrote them in his script, if that’s my understanding?

Uh, where I find </> menu item?

Thanks, mrnull, for answering.

Uh, where I find </> menu item?

When you post there is a menu bar above the typing window. On that menu bar is </>.

You still need to use move_and_slide() but the function takes no params and the return value is not used in the same way.
And you still use velocity but you don’t declare it as a variable. It is already a member of CharacterBody3D.

Your video has helped. Finally, my player moved. Thank you so much.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.