I am trying to make an rpg-style game with ursina. I want to have the camera always follow the back of the character. I tried using camera.look_at(player) but I couldn't get the camera to rotate to the back of the character when it rotated.
app = Ursina()
class character(Entity):
def __init__(self):
super().__init__(
model = load_model('cube'),
color = color.red,
position = (-0, -3, -8)
)
player = character()
print(player.forward)
print(player.forward)
camera.look_at(player)
player.rotation_y =180
def update():
if held_keys['a']:
player.rotation_y -= 2
if held_keys['d']:
player.rotation_y += 2
app.run()```
You may want to change the
origin
. Also usingparents
. I'll explain what this means in a moment.To change the
origin
(the point at which an entity is moved and rotated) to a point behind it.e.g.
But what about the camera, I hear you ask!
I'd recommend the
ursina.prefabs.first_person_controller
It may be designed for 1st person control, but you can use it for your purpose.
You will need to create a floor
entity
.That is ALL YOU NEED for the 3rd person controller. The parents and origins ensure that. It has built in WASD and Arrow Key control, with mouse control too.
@Cyber-Yosh recently asked a question for this post on how to use it without the 1st person controller. Here's how. I have commented on the changes.
You'll notice that I've not created a class (adapting this for it is easy enough), but I did not use
load_model
. This is because even if you are using your own model, you don't need to useload_model
. Simply put the name of the file (without the file extension) as astring
. This works, I've tried it.If you have any more questions, don't hesitate to ask. I am more than happy to help. If this worked, be sure to
upvote
andapprove
.