111 | | Note that in this example the Model is created by a lua script that is called in a lua tag. Lua is a scripting language that is a very powerful tool for level design. |
112 | | |
113 | | == Models == |
114 | | A level depends on its models. All finished models are stored in __../data_extern/models__. If you want to view most models in the '''Gallery''' level. |
115 | | At the moment we have several asteroids, spaceships, a satellite, two different space stations and some smaller models. |
116 | | For test purposes you can use simple models like the cube or the sphere: |
117 | | {{{ |
118 | | #!xml |
119 | | <Model mesh="cube.mesh" position="0,0,0" scale=10 /> |
120 | | <Model mesh="sphere.mesh" position="100,0,0" scale3d="10,20,20" /> |
121 | | }}} |
122 | | The attribute "scale" applies a uniform scale in all directions. By using the attribute "scale3d" you can define different scaling factors for the x-, y- and z-directions. |
| 122 | Note that in this example the Model is created by a lua script that is called in a lua tag. Lua is a scripting language that is a very powerful tool for level design. Later in this tutorial you will learn more about lua. Here is anouther example about the MovableEntity class: |
| 123 | {{{ |
| 124 | #!xml |
| 125 | <MovableEntity position="0,0,0" rotationrate="45" rotationaxis="0,0,1"> |
| 126 | <attached> |
| 127 | <Model position="0,0,0" mesh="cube.mesh" scale3D="2,2,20" /> |
| 128 | <MovableEntity position="0,0,0" rotationrate="180" rotationaxis="0,1,0"> |
| 129 | <attached> |
| 130 | <Model position="0,0,0" mesh="sphere.mesh" scale3D="1,1,10" /> |
| 131 | </attached> |
| 132 | </MovableEntity> |
| 133 | </attached> |
| 134 | </MovableEntity> |
| 135 | }}} |
| 136 | The first MovableEntity rotates slowly around the z-axis. It has a model of a cube and another MovableEntity attached to it. This second MovableEntity rotates fast around the y-axis. Notice that the first MovableEntity rotates around the global z-axis of the Scene, but the second MovableEntity rotates around the y-axis of its local coordinate system which is relative to its parent (=the first MovableEntity) |
| 137 | Inside the second MovableEntity there is another Model attached. Every Model is a StaticEntity. So here he have a nesting of WorldEntities with three layers. |
| 138 | The following example shows how to use a MovableEntity to perform a linear movement. |
| 139 | {{{ |
| 140 | #!xml |
| 141 | <MovableEntity position="100,0,0" velocity="0,0,10"> |
| 142 | <attached> |
| 143 | <Model position="0,0,0" mesh="cube.mesh" scale3D="2,2,20" /> |
| 144 | <MovableEntity position="0,0,0" rotationrate="180" rotationaxis="0,1,0"> |
| 145 | <attached> |
| 146 | <Model position="0,0,0" mesh="sphere.mesh" scale3D="1,1,10" /> |
| 147 | </attached> |
| 148 | </MovableEntity> |
| 149 | </attached> |
| 150 | </MovableEntity> |
| 151 | }}} |
| 152 | Linear movement and rotation can also be combined by setting all three parameters (velocity, rotationaxis and rotationrate). |
| 153 | You might noticed that it is possible to fly through the models. This is because the MovablEntities have no physics. Lets change that: |
| 154 | {{{ |
| 155 | #!xml |
| 156 | <MovableEntity position="0,0,0" rotationrate="90" rotationaxis="0,0,1" collisionType="dynamic" mass=10> |
| 157 | <attached> |
| 158 | <Model position="0,0,0" mesh="cube.mesh" scale3D="40,4,4" /> |
| 159 | </attached> |
| 160 | <collisionShapes> |
| 161 | <BoxCollisionShape position="0,0,0" halfExtents="40,4,4" /> |
| 162 | </collisionShapes> |
| 163 | </MovableEntity> |
| 164 | }}} |
| 165 | Never forget to change the collisionType to dynamic. Otherwise the collision shapes are useless. |
| 166 | |
| 167 | In the next example the rotating MovableEntity damages your spaceship if you touch it. |
| 168 | {{{ |
| 169 | #!xml |
| 170 | <MovableEntity position="0,0,0" rotationrate="90" rotationaxis="0,0,1" collisionType="dynamic" mass=1000 collisiondamage=0.02 enablecollisiondamage=true> |
| 171 | <attached> |
| 172 | <Model position="0,0,0" mesh="cube.mesh" scale3D="40,4,4" /> |
| 173 | </attached> |
| 174 | <collisionShapes> |
| 175 | <BoxCollisionShape position="0,0,0" halfExtents="40,4,4" /> |
| 176 | </collisionShapes> |
| 177 | </MovableEntity> |
| 178 | }}} |
| 179 | You always need to set both the collisiondamage and the enablecollisiondamage attribute. |