forked from pokepetter/ursina
-
Notifications
You must be signed in to change notification settings - Fork 0
/
faq.txt
133 lines (78 loc) · 3.58 KB
/
faq.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# arial, normal, size 1, left, width 1200
# insert doc_index_sidebar.txt
### Frequently Asked Questions
<b>How do I update ursina?</b>
# code
pip install https://github.com/pokepetter/ursina/archive/master.zip --upgrade
# text
<b>How should I structure my project?</b>
Like this:
# code
project_folder/ # create a new folder for each project
enemies.py
level.py
main.py # the starting script
player.py
player_sprite.png
textures/ # assets can be placed alongside the scripts or in a folder below
enemy_1.png
enemy_2.png
# text
<b>How do I move the camera?</b>
The camera is an Entity, so you can move and rotate it just like everything else:
# code
camera.position = Vec3(1,1,0)
# text
<b>Why should I use Python for game development. Isn't it slow?</b>
Not really. The most performance critical part are written in C++ or shader code.
Python can make you more productive as a developer and thus make it easier
to structure your project in a good way, rather than micro-optimize.
<b>How do I call a function with a delay?</b>
# code
invoke(some_function, arg1, kwarg1='some kwarg', delay=2)
# text
<b>How do I add lights?</b>
If all you want are some simple lights to make 3D shapes look more interesting,
look at the program 'lights.py' in the samples folder. For anything more complicated,
you are on your own. The DirectionalLight has shadows too, but it's recommended to use the
lit_with_shadows_shader on entities. The shadow area will be calculated based on the scene bounds,
so keep that in mind when isinstanciation the light.
<b>How can I use panda3d alongside ursina?</b>
What you need to know is that Entity is a NodePath and Ursina is a ShowBase.
You can also write custom shaders, see panda3d's shader documentation for that.
<b>How do I detect collisions?</b>
One way is with raycasts. They can hit anything with a collider.
https://www.ursinaengine.org/cheat_sheet.html#raycaster
https://www.ursinaengine.org/cheat_sheet.html#HitInfo
https://www.ursinaengine.org/cheat_sheet.html#Collider
There's also intersects(), which use the entity's collider and check if it intersects other colliders.
Like raycast(), it also returns a HitInfo.
Here's an example from the FirstPersonController:
# code
# cast a ray from the player position in the walk direction.
# only move forward if it doesn't hit anything.
origin = self.world_position + (self.up*.5) + (self.direction/2)
ray = raycast(origin , self.direction, ignore=[self,], distance=.25, debug=False)
if not ray.hit:
self.position += self.direction * self.speed * time.dt
# text
<b>How do I make a character animate?</b>
You have two options here. The first one is using .glft files and panda3d's Actor:
# code
from ursina import *
from direct.actor.Actor import Actor
app = Ursina()
entity = Entity()
#animations are stored within the file
actor = Actor("filename.gltf")
actor.reparent_to(entity)
actor.play("animation_name")
app.run()
# text
See the panda3d documentation for more info.
The second option is to use FrameAnimation3d. For that you need a sequence of models that can be loaded by ursina.
So if you have some frames named run_cycle_000.obj, run_cycle_001.obj, run_cycle_002.obj and so on,
you can load it like this:
#code
FrameAnimation3d('run_cycle_')
# text