Player Object not Visiblle

Godot Version

4.2 Linux

Question

I am following this tutorial

But I cannot get the player object to appear when I run the app.

I have created the project step by step. I’ve created the camera and even tried positioning it higher up and looking almost vertically down.

I am a complete beginner when it comes to GD script and programming in this way ( Visually with drag and drop insantiation ). I only learned Java in uni and the last time I used that in production was 25 years ago [ Yeah I’m old]

I realise that the “Your First 3D Game” tutorial is not up to date for Godot 4.2. Can anyone fix the code for me because I haven’t a clue.

My code is identical to the example code because I copy and pasted it. I understand how it’s supposed to work. It just doesn’t and I don’t know why.

Thanks in advance -

Could you post a screenshot?

Sure thing, I’m not sure it will help as it only shows a missing player blob.

Screenshot on Imgur

However I found something out this morning. The code for player.gd is as follows:

extends CharacterBody3D

# How fast the player moves in meters per second.
@export var speed = 14
# The downward acceleration when in the air, in meters per second squared.
@export var fall_acceleration = 75

var target_velocity = Vector3.ZERO


func _physics_process(delta):
	var direction = Vector3.ZERO

	if Input.is_action_pressed("move_right"):
		direction.x += 1
	if Input.is_action_pressed("move_left"):
		direction.x -= 1
	if Input.is_action_pressed("move_back"):
		direction.z += 1
	if Input.is_action_pressed("move_forward"):
		direction.z -= 1

	if direction != Vector3.ZERO:
		direction = direction.normalized()
		$Pivot.basis = Basis.looking_at(direction)

	# Ground Velocity
	target_velocity.x = direction.x * speed
	target_velocity.z = direction.z * speed

	# Vertical Velocity
	if not is_on_floor(): # If in the air, fall towards the floor. Literally gravity
		target_velocity.y = target_velocity.y - (fall_acceleration * delta)

	# Moving the Character
	velocity = target_velocity
	move_and_slide()

If I comment out the if statement ‘if not is on floor()’ then the blob appears

It would seem that it’s falling straight through the floor.

Secondly now that the blob appears - on pressing any direction key the blob moves immediately to the edge of the collision rectangle and will not move back on. I can then move the blob around but only while it’s off the edge of the play area.

Does your player have a collision shape?

I think speed 14 is pretty fast same with fall_acceleration, depends on your scale. but your player could be falling so fast it clips right past the floor

Hi thanks, yes it does.

I think I fixed it! The tutorial calls for the ground mesh to be at -1y but the collision shape to be at 0y this meant that the blob was being spawned inside the collision box and was being yeeted into the void.

I have lowered the speed as it was very fast, I have lowered the collision box to -1y and now I can move the blob around the play area as expected!

1 Like

Awesome! you can also try out using a “WorldBoundry” shape instead of a box, or making the box much taller (downward). These are usually good ways to start collision so things don’t clip through, but I understand following the tutorial! Good luck!

I will do that!

For the time being I’m doing as told. I am quickly picking up a feel for the language though.

Thanks for your support.

1 Like

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