Well, I made a major breakthrough today. Finally, some good news for once.
After posting the 'vector to angle' problem on a physics forum, I was suggested an equation that works! Those guys were fast too; they replied in less than 24 hours, so kudos to them.
Here's the equation formatted in Python, for any coders out there:
steervec = cont.actuators['Steering'].steeringVec
kartvec = kart.localOrientation[1]
kx = kartvec.x
ky = kartvec.y
sx = steervec.x
sy = steervec.y
nkx = kx / math.sqrt(kx**2 + ky**2)
nky = ky / math.sqrt(kx**2 + ky**2)
dkart = -(nky)*(sx) + (nkx)*(sy)
print(dkart)
turn = 0.06
if dkart < 0:
turn = turn
elif dkart > 0:
turn = -turn
else:
turn = 0.0
To be honest, I don't fully understand how this equations really works; but to my knowledge, it rotates the steering vector to match the kart's local vector, than relates them from there. It works wonderfully- it returns positive values when steering right, and negative values to steer left. Just what I was looking for.
However, it's not fully functional. Yet.
It seems that the steering actuator is overriding the Vehicle Wrapper. Basically, the wheels are turning and the gas is cranked, but the steering actuator stops it in it's tracks and forces it to go the set 'velocity' setting. To get this to work properly, I have to find a way to override this. Other than that, basic steering AI is almost done!
No comments:
Post a Comment