0 votes

I am following a tutorial and am brand new to the engine, coding, and game designing in general. Regardless, I do not understand why this error is popping up for me as no one else has commented a problem like mine. Something has to have changed as my code looks exactly as the tutorials.

extends KinematicBody

export var gravity = -20.0
export var wheel_base = 0.6
export var steering_limit = 10.0
export var engine_power = 6.0
export var braking = -9.0
export var friction = -2.0
export var drag = -2.0
export var max_speed_reverse = 3.0

var acceleration = Vector3.ZERO
var velocity = Vector3.ZERO
var steer_angle = 0.0

func _physics_process(delta):
    if is_on_floor():
        get_input()
        apply_friction(delta)                 #This is the problem child.
        calculate_steering(delta)
    acceleration.y = gravity
    velocity += acceleration * delta
    velocity = move_and_slide_with_snap(velocity, -transform.basis.y, Vector3.UP, true)

func apply_fcrition(delta):
    if velocity.length() < 0.2 and acceleration.length() == 0:
        velocity.x = 0
        velocity.z = 0
    var friction_force = velocity * friction * delta
    var drag_froce = velocity * velocity.length() * delta
    acceleration += drag_force + friction_force                         #This is giving me problems as well.

I have no idea why its being changed. But it looks like this. "apply_friction(delta)"

Godot version 3.3.2
in Engine by (24 points)
edited by

I edited your post to fix the formatting. Please use the "code sample" button when posting code.

1 Answer

+1 vote

It's saying apply_friction() isn't defined, because you defined this:

func apply_fcrition(delta):
by (20,479 points)

Wow, can't believe I missed that. Took me a minute to see where that was.

Can anyone help with the second problem?

"The identifier "drag_force" isn't declared in the current scope."

Same thing. You wrote drag_froce on the line before.

This is quite embarrassing.

What about this error?
"Can't get index "basic" on base "transform".

func calculate_steering(delta):
var rear_wheel = transform.origin + transform.basic.z * wheel_base / 2.0
var front_wheel = transform.origin - transform.basic.z * wheel_base / 2.0
rear_wheel += velocity * delta
front_wheel += velocity.rotated(transform.basic.y, steer_angle) * delta
var new_heading = rear+wheel.direction_to(front_wheel)

appreciate all the help regardless of how stupid the mistake's are. lol!

It's basis, not basic.

Since you are a beginner, this really isn't the best tutorial for you to start with. This is intended for people who already have some understanding of the engine and coding.

I highly recommend you start with the "Your First Game" tutorial that's in the official docs. It explains a lot of the basics that you need to know.

https://docs.godotengine.org/en/stable/getting_started/step_by_step/index.html

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.