#Need help with my script

1 messages · Page 1 of 1 (latest)

modest shale
tranquil merlin
#

in _ready

#

try adding speed = 10 or something

#

like assign it a number

modest shale
#

oh found it

tranquil merlin
#

line 20

#

if that doesnt fix it then direction.x doesnt exist

modest shale
#

alreight it works.

#

But how do I add the walk key?

stable yacht
#

The reason it said nil is because you did var speed and never set anything to it, so it had no idea what speed was supposed to be.

tranquil merlin
#

but i think it isnt getting called before movement happens

rough robin
#

If you do @export var speed := 10, you can change the speed in the inspector, which you may find more convenient than editing the script.

modest shale
#

But what do I do with my previous WALK_SPEED and SPRINT SPEED script?

tranquil merlin
#

maybe try and move that into the _process function instead of the headbob function

rough robin
#

Either move _headbob up, or move the speed assignment into _physics_process.

tranquil merlin
#

give it a shot! you won't hurt the computer!

rough robin
#

You should probably move it into _physics_process, because it doesn't seem to have anything to do with head bobbing.

modest shale
#

I moved it, but how do I add the walk key?

tranquil merlin
#

it really depends on your code

#

it looks like when the "sprint" is pressed you are using the walk speed and when it isnt you are using the sprint speed

modest shale
#

What should I do with lines 67 and 72 then? It doesn't work.

tranquil merlin
#

send another screenshot

modest shale
tranquil merlin
#

do you have an input for "sprint"?

modest shale
#

should I rename it to "shift"

tranquil merlin
#

you don't need to rename it at all

#

if it is set to something and it is being checked it should work like you want it to

modest shale
#

I don't know what I'm doing wrong.

tranquil merlin
#

that is okay

#

have you ever programmed before?

modest shale
tranquil merlin
#

if you have time

#

i did this and it helped me understand how programming works a lot

modest shale
#

In this video we create a first person character controller for Godot 4 from scratch. We also add a range of game feel features including headbob, sprinting, fov change, and inertia. This controller can be used for a variety of Godot 3D first person games, including FPS, horror, survival, RPG, etc. All of this code works with Godot 4.1.

Suppor...

▶ Play video
tranquil merlin
#

it helped me go from tutorials to a more goal oriented method when progrmaming

modest shale
#

usually my errors are from typos but this is a catistrophic issue.

#

@tranquil merlin other than the error, can something like this work?

tranquil merlin
#

yeah

#

the else statement would be better

#

no that wouldn't work sorry

#

so _ready will only run once at the very beginning

#

if you used _process or _physics_process, those get ran every frame or many times per second respectively

modest shale
#

Should I put them in one spot?

tranquil merlin
#

it can be in multiple places but const means it is constant so you don't need to set it in a function

#

the if statement should be called in one of the process functinons though

modest shale
tranquil merlin
#

like you have it, speed should be set to the value of walk speed and sprint speed

modest shale
#

Should I take a break from this for a bit?

tranquil merlin
#

if you want

#

i really would recommend a general programming course, the one I sent is free

#

it really helps in understanding why/how things work

modest shale
#

I want to get as much progress as possible before I become an adult and do this full time.

tranquil merlin
#

if you want to make serious progress itd behoove you to learn such things then! an architect must understand the engineering before they can design a building!