Search code examples
pythonursina

Python Ursina car move direction


I want to make some racing game in Python Ursina. I made my car model with rotating (changing drive directions), but I want to make it drive, where car is rotated using "w" key. But it still go only direction up, even when it's rotated and I want it to go direction which is car facing.

Code is here:

def update():

player.y += held_keys['w'] * time.dt * 0.7
player.y -= held_keys['s'] * time.dt * 0.7

if held_keys['d']:
    player.rotation_z = player.rotation_z + time.dt + 2.5

if held_keys['a']:
    player.rotation_z = player.rotation_z + time.dt - 2.5

Thanks for your time!


Solution

  • Do player.position += player.up instead, to move it in the up direction, taking rotation into account.