Hi, I created these two codes to get a character’s rotation angle differential, to tilt it when it rotates in some direction, but when the character completes a complete revolution, it rotates quickly within its axis, which stays ugly to see. I wonder if there is any way around this, I would appreciate any help.
The problem:
This was created recently, in a simpler way, but it still doesn’t work well.
own = self.object
position = own.worldTransform * own.worldPosition
self.posição_atual = position
result = self.current_position.xy.angle_signed(self.old_position.xy, 0.0)
rotation_limite = 0.02
if result > rotation_limite: result = rotation_limite
if result < -rotation_limite: result = -rotation_limite
abs(1-smooth))))
xyz = own.localOrientation.to_euler()
xyz[1] = ((result*radians(300))*(vel_*0.3))
own.localOrientation = xyz.to_matrix()
self.old_position = position
This other code works much better, but it still has problems with what I described above.
own = self.object
rotaion_limite = 1.0 #here is a floating value entry that varies during gameplay
if rotaion_limite > 0.02:
rotaion_limite = 0.02
diference = (Vector(self.wrd_oldori) - Vector(own.worldOrientation.to_euler()))[2]
if diference > rotaion_limite:
diference = rotaion_limite
if diference < -rotaion_limite:
diference = -rotaion_limite
smooth = 0.95
self.wrd_smoothori = ((self.wrd_smoothori * smooth) + (((diference *radians(300))*(vel_*0.3) * abs(1-smooth))))
xyz = own.localOrientation.to_euler()
xyz[1] = self.wrd_smoothori
own.localOrientation = xyz.to_matrix()
self.wrd_oldori = own.worldOrientation.to_euler()