3D Theory - Games Generation Example

Here are some proposed nodes to exten x3d to allow physics animation.

As an example of how to use this for a games generator, here is a very simple 'asteroids type' game.

It starts off with a few large rocks moving about the screen, when the large rocks hit something then it splits into two medium objects, when the medium object hits something then it splits into two smaller objects. If something hits a small object then it just disappears.

If something hits the ship then the game ends.

Listing

#VRML V2.0 utf8
DEF large Multiple {
initialInstances 2
maximumInstances 10
children [
Transform {
children [
Shape
{
appearance Appearance
{
material Material {
diffuseColor 0.0 1.0 1.0
}
}
geometry
Box {
size 0.2 0.2 0.2
}
}
Kinematics {
randomMinMax 0.0 0.01
enable TRUE
}
CollisionDetect {
}
DEF largeCollision CollisionAction {
collideWith [bullet,
]
actionThis delete
actionOther delete
createNew medium
createNumber 2
createAt collide
counter 0
}
Constraint {
constrainTranslation moveWithinBounds
minTranslation -1.0 -1.0 -1.0
maxTranslation 1.0 1.0 1.0
action bounce
}
]
}
]
}
DEF medium Multiple {
maximumInstances 10
children [
Transform {
children [
Shape
{
appearance Appearance
{
material Material {
diffuseColor 0.6 1.0 0.0
}
}
geometry
Box {
size 0.1 0.1 0.1
}
}
Kinematics {
randomMinMax 0.0 0.01
enable FALSE
}
CollisionDetect {
}
CollisionAction {
collideWith [bullet,
]
actionThis delete
actionOther delete
createNew small
createNumber 2
createAt collide
counter 0
}
Constraint {
constrainTranslation moveWithinBounds
minTranslation -1.0 -1.0 -1.0
maxTranslation 1.0 1.0 1.0
action bounce
}
]
}
]
}
DEF small Multiple {
maximumInstances 10
children [
Transform {
children [
Shape
{
appearance Appearance
{
material Material {
diffuseColor 1.0 1.0 0.6
}
}
geometry
Box {
size 0.05 0.05 0.05
}
}
Kinematics {
randomMinMax 0.0 0.01
enable FALSE
}
CollisionDetect {
}
CollisionAction {
collideWith [bullet,
]
actionThis delete
actionOther delete
counter 0
}
Constraint {
constrainTranslation moveWithinBounds
minTranslation -1.0 -1.0 -1.0
maxTranslation 1.0 1.0 1.0
action bounce
}
]
}
]
}
DEF ship Transform {
translation 0.5 0.0 0.0
children [
Shape
{
appearance Appearance
{
material Material {
diffuseColor 0.0 1.0 1.0
}
}
geometry
Sphere {
radius 0.02
}
}
CollisionDetect {
}
CollisionAction {
collideWith [bullet,
]
actionThis delete
actionOther delete
createNew medium
createNumber 2
createAt collide
counter 0
}
Multiple {
initialInstances 20
maximumInstances 20
children [
DEF bullet Transform {
rotation 0.0 0.0 1.0 0.0
children [
Shape
{
appearance Appearance
{
material Material {
diffuseColor 1.0 1.0 0.0
}
}
geometry
Box {
size 0.01 0.01 0.01
}
}
DEF moveBullet Kinematics {
randomMinMax 0.0 0.04
enable FALSE
}
CollisionDetect {
}
CollisionAction {
collideWith [bullet,
]
actionThis delete
actionOther delete
createNew medium
createNumber 2
createAt collide
counter 0
}
Constraint {
constrainTranslation moveWithinBounds
minTranslation -0.3 -0.3 -0.3
maxTranslation 0.3 0.3 0.3
action restart
}
]
}
]
}
DEF touch TouchSensor
{
isOver FALSE
}
]
}
Transform {
center 0.0 0.0 0.0
scale 0.0020 0.0020 0.0020
translation 0.25 0.04 0.8
children [
DEF score Score
{
}
]
}
ROUTE
largeCollision.count TO score.count
ROUTE
touch.isOver TO moveBullet.enable

metadata block
see also:
Correspondence about this page

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2022 Martin John Baker - All rights reserved - privacy policy.