admin管理员组

文章数量:1123788

I'm making a simple space simulator, and all I need is to fly around. I managed to make camera move around but I cannot make it rotate correctly along its axes. I couldn't make FirstPersonController fly, so I decided to make my own camera.

This is the movement in xyz:

direction = Vec3(camera.forward * (held_keys['w'] - held_keys['s']) + camera.right * (held_keys['d'] - held_keys['a']) + camera.up * (held_keys['e'] - held_keys['q'])).normalized()

camera.position += direction * speed * time.dt

Rotation along 1 axis works well:

camera.rotation_y += mouse.velocity[0] * sensitivity

When I add rotation_x, it's a mess. It rotates along world X axis no matter the direction. The same with z axis.

I tried to add camera_pivot entity and rotate it along one axis and camera itself along another axis, but it still doesn't work properly:

camera_pivot = Entity()

camera.parent = camera_pivot

camera.position = (0, 0, 0)

camera.rotation = (0, 0, 0)

update section:

camera_pivot.rotation_x -= mouse.velocity[1] * sensitivity

camera.rotation_y += mouse.velocity[0] * sensitivity

Upd: EditorCamera has the same problem. If you look up, then you can't look right/left, the view is rotating in front of you.

本文标签: pythonHow do I rotate camera in Ursina engineStack Overflow