#errors when trying to make a car
18 messages · Page 1 of 1 (latest)
i included it along with the screenshots
so, any ideas?
also, i think i found the line that's not working, idk why tough
car_mesh.transform.origin = ball.transform.origin + sphere_offset
The code seems cut off i dont see anything related to actually moving
weird, do you see it now?```extends Spatial
node refs
onready var ball = $Ball
onready var car_mesh = $model
onready var ground_ray = $model/RayCast
pos du mesh par rapport a la sphere
var sphere_offset = Vector3(0,-1.0,0)
var acceleration = 50
degrés de steer
var steering = 21.0
var turn_speed = 5
tourne pas en dessous de cette speed
var turn_stop_limit = 0.75
input vars
var speed_input = 0
var rotate_input = 0
func _ready():
ground_ray.add_exception(ball)
func _physics_process(_delta):
# garde la pos du mesh correct
car_mesh.transform.origin = ball.transform.origin + sphere_offset
# accelere dans la direction de la caisse
ball.add_central_force(-car_mesh.global_transform.basis.z*speed_input)
func _process(_delta):
if not ground_ray.is_colliding():
return
# 1 si accelere, -1 si freine, * acceleration = vitesse
speed_input = 0
speed_input += Input.get_action_strength("accelerate")
speed_input -= Input.get_action_strength("brake")
speed_input *= acceleration
# 1 si gauche, -1 si droite, * angle de steer = tourner
rotate_input = 0
rotate_input += Input.get_action_strength("left")
rotate_input -= Input.get_action_strength("right")
rotate_input *= deg2rad(steering)
No
Oh wait i do
Or rather there is movement code but i dont see a way for it to actually work
in func _process, speed_input is defined, and in physics process i think we make the ball go forward using that speed_input
using add_central_force
Maybe take out the conditional of being i n the ground and print out speed_input
well, i can now go forward and backwards, but turning doesn't work (and also the camera doesn't follow the car, but it may simply be a node tree error
it is set to 0 by default and goes to 50/-50 when i press the keys
oh wait actually it's normal that i can't steer yet
but why does the camera not follow the car? i'm pretty sure it should work like that
ok nvm, figured it out, thanks for the help
can you mark this as solved, and close it instead of deleting the original message?