Add object at runtime, CameraMovement demo

Hi there Blenderers,

I started using Blender a few weeks ago and asked some questions on this forum.
In honour to those who kindly helped me I now like to share the result of my first struggle with this great environment.
I would like to thank: Moguri, Captain Oblivion, Maurice Raybaud, OTO, -[Killer]-, J09, Chaser and DichotomyMatt for their help. I learned a lot from them.

There were several things that I wanted to learn, before taking Blender into real game-making (wich has’nt started yet).

1e I wanted cameramovent like I am used to:

  • Mouse-cursor on leftside of screen = turn left, -on rightside of screen turn right.
  • Mouse-cursor on top-side of screen move forward, -on low-side move backward.
  • Mouse-wheel up, camera moves up but keeps sight on vanishing point on horizon, -mouse-wheel down camera down.
  • Let camera not go through groundplane and keep hight with respect to groundplane when moving.
  • Middle mouse button pressed camera jumps to position where mouse was pointing at

2e I wanted to be able to add a lot of objects to my scene.
(I would like to add new objects (generated during runtime), but that seems to be impossible. Objects must exist at startup time and they must exist on an unvisible layer)

3e I wanted to control at least the movement of these new objects.
(But like to control much more)

All of this can be done with Blender and are demonstrated in the…okay lets call it a game … I share with you.

Got interested? download it here:
MouseMovement see above,
LMB = add object (cursor must be on an object (preferably on green groundlevel
RMB = Give balls a force in the direction of place where mousecursor clicked and will jump up a little

If someone likes to know more about it, just ask me.
(I can write a tutorial, if you’d like me to).

Minimum Knowldge to understand what I did:

  • Some knowledge of Pyhton,
  • You should a least have some knowledge of the game-engine and a bit of how to use logicbricks.

(Sorry to those who digg in to my blend-file; Comments in the Python-scripts and Names are partialy in English and Dutch I did not (yet) translate all of it; hollidays are over and I just hav’nt much time to spare just now)

:):):slight_smile: And at last :):):);

If you don’t like It, do not understand a bit of how things are done, think I am a mad man or what ever . . . . . . !!!
Toddlers will like playing with it;
I am sure because my two years old daughter loves it.

Thanks for helping
Greeting to you all

A few weeks!?
The python scripts are long enough for me not want to read it :wink:

i like the way you’ve got the objects being added in above the landscape… and you’ve translated the mouse position into a 3d position…

Very impressive!

(I would like to add new objects (generated during runtime), but that seems to be impossible. Objects must exist at startup time and they must exist on an unvisible layer)

That isn’t entirely true. Do some searching, I’ve seen scripts before that allow you to create objects in game. The example I saw was making houses.
I noticed you were moving your empty (Toevoeger) using the motion actuator, you can modify the objects position purely using python. E.g.
own = GameLogic.getCurrentController().getOwner()
You can use own.getPosition() to find out where the object is and adjust the values acordingly.
Same effect I guess but it gives you one less actuator to clutter up the screen.


What did I do for you?

Hi Killer,

You were the first to give a reaction to my thread:,

After that I could go on chasing the right way to use your suggestion.
By trying your sugestion I learnt that not all sensors (not even all mouse-sensors) have the same methods.
That was a good lesson for me. So your suggestion gave me a boost.

And: Because of you I learnt to use this page extensifly:

Greetings to you


Hi TheDave

Thanks for your information,
I have seen a lot of python-scripts, but I could not find any way to create objects at runtime.
There were even several reactions on this forum that gave me the impression this couldn’t be done.
I also did a lot of experiments myself but I could not find a way too.

Okay I will keep trying,
If you should find a ‘link’ please post it here or pm-me; that would be very nice

Greetings to you


Glad I could help.

Here ya go. I got it by googling “python blender create object”

There ya go =) I just googled “python blender create object”

Fyi, I noticed in your other post you were having troubles with the ray only pulsing once when it hit an object, which you fixed by using an always sensor. If you turned on the pulsing button for the mouseover sensor then it would save you having to use that always sensor. Plus it means the script isn’t running unnecessarily. Alternatively if you wanted the script to run constantly while something IS NOT positive then you can turn on the negative pulse button.

Actuator => edit object => add object => object name (in an inactive layer)

why don’t you use it ?

if you need them for python script, add them to a list

// create list :
GameLogic.list = []

// add object

Hey and sorry Alex,

You lost me there
What a I not using?

I add objects (balls) like this
(‘Toevoeger is the empty where objects will emerge in the visible part of the scene’)

Toevoeger.setPosition([Xhit,Yhit,Zhit+0.2] )
VoegToe = cont.getActuator(“VoegToe”)
VoegToe.setObject( “Bol” )
VoegToe.setLinearVelocity(0.2,0.1, 0)

Thats what I ment with:
Actuator => edit object => add object => object name (in an inactive layer)


You did check the link on the end of my first post on this subject did you
(for some reason the first-one does not work (for me atleast it doesn’t ))
This is the good one:

Euh Alex,

Can you add objects to a game, when the GE is running?
I mean objects that are not predefined, but objects that kind of evolved during game-play.


ok i see the blend

it was a misunderstanding :smiley:

so if i understand, you want to create an object that it don’t exist in any layer ? why ?

i think it’s possible, but i don’t understand why you need it

Hi Alex,

At the time I posted the first question about this subject I was working on a biology-like program.
The idea was to let ‘things (=0bjects= Meshes)’ evolve while time moved on.
I have put this idea aside for the moment, because it proves impossible to implement (I think) with Blender.
Though others on this forum would like to use it to deform meshes during gameplay.
For me this subject is not important at this moment, but I am still interested.