HeyHo,
Ich bastel mir grad ein Script, in dem ein Ped mich zu einer Koordinate fährt.
Das ganze funktioniert soweit auch schon.
Jedes mal wenn das Fahrzeug zum nächsten Wegpunkt fährt wird die Rotation Z zum Wegpunkt hin angepasst.
Dabei werden Rotation X und Y auf 0 gesetzt. Schlecht bei schrägen/ steilen Straßen, dann buggt das Fahrzeug nur rum.
Leider kann man nicht ausschließlich die Rotation Z ändern, oder irre ich mich da?
Hab im Wiki unter getElementMatrix eine Funktion gefunden die anscheinend genau das macht was ich brauche, nur funktionierts nicht - Das Fahrzeug wir mal auf die Seite gelegt etc...
Bräuchte also sogesehen eine Funktion die mir die Rotation X und Y berechnet.
Mal den ausschnitt aus meinem Code.
local function updateRotationToNextWaypoint()
local wp = tmp.nextWayPoint
if (wp == #tmp.marker) then
stopDriving()
return
end
local x, y, z = getElementPosition(tmp.vehicle)
local rx, ry, rz = getElementRotation(tmp.vehicle)
local rotZ = findRotation(x, y, tmp.paths[wp].x, tmp.paths[wp].y)
local rx, ry, _ = getPositionFromElementOffset(tmp.vehicle, rx, ry, rotZ)
local diff = math.abs(math.floor(rotZ - rz))
if (diff > 5) then
setElementRotation(tmp.vehicle, rx, ry, rotZ)
end
end
function findRotation(x1, y1, x2, y2)
local t = - math.deg(math.atan2 (x2 - x1, y2 - y1))
if t < 0 then t = t + 360 end
return t
end
function getPositionFromElementOffset(element,offX,offY,offZ)
local m = getElementMatrix ( element ) -- Get the matrix
local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform
local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2]
local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3]
return x, y, z -- Return the transformed point
end
Alles anzeigen
Hoffe ihr könnt mir da weiterhelfen
Lg
Lars