attempting to get updated position for car rotation.
Posted: Sun Jun 21, 2020 7:33 am
so i have to cars. 1 is the car driven by the player and the other is updated by script to maintain its position relative to the car. im trying to adjust the position anytime the players car turns to maintain the second car in a relative position of the left side of the vehicle.
the current code i have will rotate the auto pilot car but it rotates the wrong way in comparison to the players car turning direction and tends to freak out when the player is facing south.
how do i get it so that the autopilot car always stays on the vehicles left side even while rotated?
the current code i have will rotate the auto pilot car but it rotates the wrong way in comparison to the players car turning direction and tends to freak out when the player is facing south.
Code: Select all
global.left_car.orientation = global.car.orientation
local degrees = global.car.orientation*360
local rad = (degrees*(math.pi/180))*-1
local left_car_pos
local old_x = global.left_car.position.x
local old_y = global.left_car.position.y
local pivot_x = global.car.position.x
local pivot_y = global.car.position.y
old_x = old_x - pivot_x
old_y = old_y - pivot_y
local left_x = (old_x*math.cos(rad) - old_y*math.sin(rad)) + pivot_x
local left_y = (old_x*math.sin(rad) + old_y*math.cos(rad)) + pivot_y
left_car_pos = {left_x,left_y}
global.left_car.teleport(left_car_pos)
global.left_car.speed = global.car.speed