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:
Node
I->CharacterBody3D
I->Player with Gscript
I–>Camera Pivot
I–> Camera3D
I–>CollisionShape3D
Its still not moving. I input WASD to Input Map and got the same result.
Here’s the Gscript
Blockquote
extends CharacterBody3D
var gravity = Vector3.DOWN * 12
var speed = 4
var jump_speed = 6
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 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?
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.