Create objects with kode

How to create objects dynamically using kode

As well as placing objects into your Edit World using the prop gallery, you can create objects dynamically using kode (also called spawning). This tutorial shows you how to

  1. Create a single object
  2. Create multiple objects
  3. Specify position of object
  4. Change the orientation of the created object

Choosing an object to create can be achieved by selecting it in the prop gallery, picking an object in the world to copy using IWP, picking a template using IWP, selecting an object using a pre-set object variable.

1.Create a single object

When creating a single object you have to ensure you are creating in a single frame, and not asking it to create over and over (such as [started to] or [once]).

WHEN [once] DO [create][gallpicker:object]

2.Create multiple objects

Method 1: Duration tile

Instead of asking it to create once in a frame, let it create over multiple frames but specify how many. It will create 1 object per frame then stop.

WHEN [duration timer][4][in frames] DO [create][IWP:object]

Method 2: For each tile

This will run the line 4 times then stop

WHEN [for each of][4] DO [create][IWP:object]

3. Specify position of object

If you use create without specifying a position the object will be created at the owner’s ? socket. If you are creating using a logic cube or other invisible non collidable object than you can use that object’s position as your spawning point.

WHEN [once] DO [create][IWP:object][at position][position]

To specify another object’s position use

WHEN [once[ DO [create][IWP:object][at position][IWP:other_object][position]

You can also use in-world vectors

Method 1: One vector coordinate per line

WHEN DO [vectorvar:goblin][x]=[0.567484]
WHEN DO [vectorvar:goblin][y]=[0.1]
WHEN DO [vectorvar:goblin][z]=[-0.367647]
WHEN [Once] DO [create][goblin][at position][vectorvar:goblin]

Method 2: Specify vector in the position kode

This uses less lines of kode but is harder to work out at a glance. It uses world up, west and north instead of y, x and z.

WHEN [once] DO[create][at position][zero][+][world up][x][0.1][+][west][x][0.567484][+][north][x][-0.367647]

To create a random position within a set radius

WHEN DO [vectorvar:goblin][=][position][+][random vector][circle][radius][10][inside]
WHEN [Once] DO [create][goblin][at position][vectorvar:goblin]

4. Change orientation of object

When you create any object in kode it will have a default world up and will face south. So, if you want the object upside down or facing west you have to specify it in the kode.

If your object is in its default orientation (i.e. upright) and you just want it to face a different direction you could try creating it with its forward vector facing another object (such as an invisible logic cube, or object in your world).

WHEN [Once] DO [create][goblin][at position][IWP: logic cube][position][towards][IWP: tree]

If your object is a character and will move, then you also need to add this to its brain or it will continue to face the object it was facing when first created.

WHEN [once] DO [forward][=][forward]



Comments are closed.

Website Powered by

Up ↑

%d bloggers like this: