My Issue
I am using the Panda3D
wrapper for Python
to run some 1st person game tests. I would like the collider of the ursina
camera type called the FirstPersonController
to extend its collider over the sprite. I have tried (without really knowing how as there aren’t many tutorials on Ursina) using a BoxCollider()
but I didn’t really get how to do it. Can anyone help me?
My Code
JavaScript
x
49
49
1
from ursina import *
2
from ursina.prefabs.first_person_controller import FirstPersonController
3
4
5
6
class Player(Entity):
7
def __init__(self, parent):
8
super().__init__( # super() is used to access things from the inheriting class (in this case the Entity class)
9
model = 'cube',
10
color = color.red,
11
parent = parent
12
)
13
14
15
class Floor(Entity):
16
def __init__(self):
17
super().__init__(
18
model = 'cube',
19
scale = (40, 3, 40),
20
color = color.rgb(23, 45, 105),
21
position = (0, -20, 0),
22
collider = 'box'
23
)
24
25
26
27
28
app = Ursina()
29
30
window.fps_counter.enabled = False
31
window.fullscreen = True
32
33
34
35
cam = FirstPersonController()
36
player = Player(cam)
37
38
39
floor = Floor()
40
41
42
43
def update():
44
if held_keys['escape']:
45
application.quit()
46
47
Sky()
48
app.run()
49
Please help, all suggestions are helpful!
Advertisement
Answer
To show a 3rd person perspective, you can move the global camera back:
JavaScript
1
6
1
def to_first_person():
2
camera.position = (0, 0, 0)
3
4
def to_third_person():
5
camera.position = (0, 0, -3)
6
You could either do this once when loading the game or switch back and forth via keyboard inputs:
JavaScript
1
6
1
def input(key):
2
if key == '1':
3
to_first_person()
4
if key == '3':
5
to_third_person()
6