Collision detection

Hi guys,

Great support here btw. I have another doubt.

Basically, I’m using a collison sensor on one object on the scene and linking it to my python script and works fine. But let’s say I’ve got hundreds of objects. Now I don’t want to have to link all these objects to the same collision script. That sounds just draft… so what is the best practice?

Do I just create a property and assign all the same properties to all those objects. And do collision detection on that property

Also another question. Is it possible to create an entire game with just two logic bricks (always sensor and one python script?)

Thanks in advance!

Generally you would create one object with a collision sensor on an inactive layer and then just add multiple instances of the object as needed.

And yes, it’s possible to create an entire game with just an Always sensor attached to a Python controller.

From your question I assume you noticed that this sounds not really efficient. I’m pretty sure you are talking about your poor fingers clicking that much around. I talk about the processing time of your scene. Indeed often there is a relation (but in a lot of cases therei not :D).

Think about that: how many objects are involved in a collision?

-> yes, at least two.

How many collision sensors doe you need?

-> yes, just one.

As we have at least two objects, but only one sensor, what object should sense the collision?

-> It depends on your situation. Think about it!

I do not think that properties collide with objects :wink:

Yes, it is possible. But makes that any sense?

As we have at least two objects, but only one sensor, what object should sense the collision?

-> It depends on your situation. Think about it!

Interesting… To be honest I was confused about collision detection, in (flash AS3 lol I know, I know hangs head in shame) we would do:

if object1.collides(object2)

I guess I was looking for a similar analogy here. Maybe you only need collision sensors on the player and the enemies.

I do not think that properties collide with objects

Yes but what I meant was, you detect collision with an object then you can check if that object has a certain property to detect and change how it reacts in the scene? :wink: I’m sure that would make logical sense right?

The collision sensor basically does what you describe above, but you configure it via the GUI rather than code.

You can filter the hitObjects that collide with the object that senses the collision by assigning a property name in the property field (alternative a material name).

The difference to the Python code is that it runs in native code = faster. This makes a lot of sense as you need to perform this check at each single frame.

If you need a finer filter (e.g. several properties, object names …) you can filter via Python by checking the attribute hitObjectList.

The difference to the Python code is that it runs in native code = faster. This makes a lot of sense as you need to perform this check at each single frame.

Sorry for asking a silly question, but I’m a bit confused, I thought python was a scripted language and not native/compiled.
Does it behave differently in the bge? Thanks in advance.

Does it behave differently in the bge

Not really, python is just code that you need if you want to finetune actuators/sensors.
logic bricks are limited in what they can do, so you switch to python if you want to get more out of it.

like the collision sensor, with bricks you can do allot but only with 1 object at a time.
the sensor can register tons of collisions at once, so that sensor keeps track of them in a list.
this list can be read/adjusted trough python.

so basically if you want a simple game (if collide with wall stop moving) logic is good to use.
if you want the same sensor to stop at a wall, stop at an edge or check if you hit the ground at the same time, then i recommend using python, it can then read the properties/names of the object collided with and start the proper action.

No I was asking if python is compiled, monster says it runs “native” implying compiled and executed as opposed to interpreted, where interpreted languages are the slowest of all type of programming languages. Java and dotnet coming somewhere in-between with their ‘Just in time’ byte code crap.

Python is interpreted. The language itself is compiled to byte-code (*.pyc), which is then run (for the BGE) in a C VM.

Monster wrote “the difference TO logic bricks is that THEY are compiled”, meaning that logic bricks are compiled in C++ :slight_smile:

What exactly are you saying the the logic bricks should be faster? Man I really dislike logic bricks it’s like spaghetti junction!!!

C++ code will perform the same elementary tasks faster than Python, because there is no interpreter / dynamic type resolution.
Logic bricks execute many operations in C++, so as task complexity grows, a like-for-like comparison will typically be faster in C++.

Python is more flexible than logic bricks (and can be used to “psuedo-extend” them). This comes from an avid pure-python advocate.

Ok thanks, I’m not going to be too conerned which method I use. It’s hardly going to be a game with masses of AI etc. Just one character jumping around.

****Edit, Just sent you a PM let me know if you can help?