Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | StrikerSVX |
Hi everybody and sorry for my bad english i’m not too fluent and i’m new to godot too, i started doing some games in the engine and im liking it very much, i tried unity one time but i never could do anything on that engine until i found godot and some tutorials over the internet, today i can do some plataform games and rpg like pokemon and zelda, but none of then are what i really wanted to do, one of my projects was to make a racing game with police like NFS Carbon, i started drawing some cars and roads and i did make a demo, but my code to the car of the game it’s too simple, it drives good but doesn’t fell like a car, my code is this here:
extends KinematicBody2D
export (int) var speed = 150
export (float) var rotation_speed = 1.5
var velocity = Vector2()
var rotation_dir = 0
func get_input():
rotation_dir = 0
velocity = Vector2()
if Input.is_action_pressed('ui_left'):
rotation_dir -= 1
elif Input.is_action_pressed('ui_right'):
rotation_dir += 1
if Input.is_action_pressed('ui_up'):
velocity = Vector2(speed, 0).rotated(rotation)
elif Input.is_action_pressed('ui_down'):
velocity = Vector2(-speed, 0).rotated(rotation)
func _physics_process(delta):
get_input()
if velocity != Vector2():
rotation += rotation_dir * rotation_speed * delta
move_and_slide(velocity)
I dunno how to post my code better, but i would love if someone could help me it this code, everything that this code do its to move my car forward, backward and turn only if the car is in moviment like every car would do, but it doesn’t accelerate like a car and don’t have a extra force pushing my car left and right for drifting it, if someone could at least help me add some acceleration to my car, i would totally apreciate it. (and again sorry for the bad english…)