Unable to Steer vehicle with Left and Right arrows

soham0243soham0243 Posts: 1Member
edited July 22 in General Support

Hello,
I am trying a simple car controller tutorial (Ref: Godot Vehicle Tutorial - Youtube) with a simple car (not the same car used in tutorial)
I am facing two problems .
1. I am trying to execute the same script (after attaching to a different model). When I run the scene the controller behaves weired (For example if I press left arrow then it goes to left at first but I can't steer it to right. Same thing for right arrow - it works at the beginning nut then not working). My script is the following

extends VehicleBody

export var MAX_ENGINE_FORCE = 200.0
export var MAX_BRAKE_FORCE = 5.0
export var MAX_STEER_ANGLE = 0.5

export var steer_speed = 5.0

var steer_target = 0.0
var steer_angle = 0.0

export var JOY_STEERING = JOY_ANALOG_LX
export var steering_mult = -1.0
export var JOY_THROTTLE = JOY_ANALOG_R2
export var throttle_mult = 1.0
export var JOY_BRAKE = JOY_ANALOG_L2
export var brake_mult = 1.0

 # Called when the node enters the scene tree for the first time.
func _ready():
    pass # Replace with function body.
func _physics_process(delta):
    var steer_val = steering_mult * Input.get_joy_axis(0,JOY_STEERING)
    var throttle_val = throttle_mult * Input.get_joy_axis(0,JOY_THROTTLE)
    var brake_val = brake_mult * Input.get_joy_axis(0,JOY_BRAKE)
    # overrules for keyboard
    if Input.is_action_pressed("ui_up"):
        throttle_val = 1.0
    if Input.is_action_pressed("ui_down"):
        #brake_val = 1.0
        throttle_val = -1.0
    if Input.is_action_pressed("ui_left"):
        print("left arrow pressed")
        steer_val = 1.0
    if Input.is_action_pressed("ui_right"):
        print("right arrow pressed")
        steer_val = -1.0

    engine_force = throttle_val * MAX_ENGINE_FORCE
    brake = brake_val * MAX_BRAKE_FORCE

    steer_target = steer_val * MAX_STEER_ANGLE
    if(steer_target < steer_angle):
        steer_angle -= steer_target * delta
        if(steer_target > steer_angle):
            steer_angle = steer_target
    elif(steer_target > steer_angle):
        steer_angle += steer_target * delta
        if(steer_target < steer_angle):
            steer_angle = steer_target

    steering = steer_angle
  1. I am facing problems with suspension. I changed rest length in vehicle wheel but the wheels keep going through the car in vertical direction.
    Suspesion Problem
    I tried lowering the wheel then varying the rest length by assuming the position of the wheel in rest but no luck.
  2. Wheels does have material on viewport but not on test
  3. The test freezes sometimes. (This is not a regular issue anyway, it happens sometimes)
    (If up and down arrow are pressed at exact same time)
    Ref : Files for the car controller - GODOT_3.2_simple_car_controller
    NOTE : In collision body section, I changed plane to box collider for ground

Tags :

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file