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.
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
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.
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.
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.
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.