Brackeys 3D Tutorial Question

Godot Version

4.2.2

Question

I have been working very slowly through the Brackeys Tutorial/overview on 3D with Godot from YouTube located at:

At approx the 12min mark he tells us about a FPS “proto-controller” he has made to work as a default character controller for the rest of the tut and could download it.

In any case, I couldn’t import the files the way he did on the vid, so, I exited Godot, copied the files I needed into the “addons” directory, that we were told to create, and when I re-opened the Godot and went to the game, I got the following errors:

  • res://addons/proto_controller/proto_controller.gd:91 - Parse Error: Function “get_gravity()” not found in base self.

  • modules/gdscript/gdscript.cpp:2726 - Failed to load script “res://addons/proto_controller/proto_controller.gd” with error “Parse error”. (User)

So, I had no idea what to do here?!? In any case I tried loading the TSCN file into the project just in case and got other errors.

I then tried for the sake of it removing the offending line with a:

print("Jumping");

Which duly worked however I have no idea how to stop the jumping once started. The code causing the error in full is:

if has_gravity:
	if not is_on_floor():
		velocity += get_gravity() * delta
		#print("jumping");

If anyone can give me some advice on what to correct this line to, to get it working would be very much appreciated.

Regards.

Godot doesn’t use semi-colons ;, not sure why the tutorial would want you to program inside the addons folder, by default Godot disables warnings coming from that folder.

Yeah I know force of habit I am afraid. I have programmed so much in C, C++, Java and even C# that it’s ingrained. if a line doesn’t have a semi-colon at the end it LOOKS wrong same with “if” statement they have to be encased in brackets and multiple brackets if more than one. The reason why this doesn’t is because it wasn’t my code.

I’ve never heard of an “addons” folder before and I’ve never set foot in 3D with Godot before, so, I did what I was told. So, I have this error and I don’t know what to do about it :anguished:

Guess I just have to disable the Jumping :disappointed:.

addons is not just for 3D development, any AssetLib or new plugin will be put in addons.

Looks like your proto controller isn’t the same as the tutorial’s, the main difference being the input is missing.

# Apply jumping
if can_jump:
	if Input.is_action_just_pressed(input_jump) and is_on_floor():
		velocity.y = jump_velocity

from github

You had me worried there for s moment… but, yes, I have those lines, they are below the offending code which is just above it here:

# Apply gravity to velocity
	if has_gravity:
		if not is_on_floor():
			velocity += get_gravity() * delta
			#print("jumping");

I’ll try adding it to velocity.y like I do in 2D, see if that works. Stupid me, it’s the get_gravity() function that doesn’t work. Bah humbug.

1 Like

proto_controller.gd extends CharacterBody3D. In line 91 it is trying to call the method get_gravity() on its class or one of its parent classes. In Godot 4.3 we can find this method in CharacterBody3D’s parent class PhysicsBody3D, but in Godot 4.2 the method is not present in PhysicsBody3D.

tldr: try Godot 4.3, the current stable version, that should work.

2 Likes

Aha - didn’t think of that. I am still working on a 2D game that WILL be broken if I change it to 4.3 - something wrong with the animation player. However, if I were to open this game in 4.3 there shouldn’t be a problem(s).

I will try it out and report back!

PS Success!!! Thankyou so much @Sanne for replying getting that working is a load off my shoulders.

Regards.

1 Like

You’re welcome, glad it’s working!

A tip, In case you’re not aware, you can run multiple Godot versions side by side if you activate self contained mode. I’m using it to test out betas but still use stable for my projects.

1 Like

Before Godot 4.3 you had to get the gravity from the project settings.

var gravity := ProjectSettings.get_setting("physics/3d/default_gravity")

In case you don’t want to switch to a newer version yet.

2 Likes

I was looking at creating a constant for gravity like I did in 2D, but, it wasn’t defined anywhere in the code. I had no idea you could set it with a default value in get_setting() function.

I learnt another way in a Udemy course to make the jumping a little less, ummm, floaty, the value after calculation was: 2508. So, I was looking for something along those lines.

Thankyou for making me aware of this.

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