[Python] Rotating smoothly in python ursina

Discussão em 'Python' iniciado por Stack, Março 27, 2025.

  1. Stack

    Stack Membro Participativo

    I'm currently writing a game and in one of my Entity subclasses, I need it to rotate "smoothly" instead of doing a teleporting esque rotation. Right now I have

    def smooth_look_at(self, target_position, speed = 10):
    global target_rot
    if not self.pass_: # only set the target rotation and the increment once per thing looked at
    target_rot = (target_position - self.position)
    self.increment = target_rot.y / speed
    self.pass_ = True
    self.rotation.y += self.increment * time.dt #only rotate around the y axis
    if self.rotation == target_rot: #if you reach your rotation goal, return true, reset pass_ for the next time you need to rotate
    self.pass_ = False
    return True


    In the update(self) function, walk gets called every time i need it to, and in the walk() function, there is a line :

    if not self.smooth_look_at(self.target_position):
    return


    so it waits until it finishes turning. what ends up happening is it never turns. What am I doing wrong and how can I fix it?

    Continue reading...

Compartilhe esta Página