New game engine developer, added collision.hitPosition, and collision.hitNormal

I am very happy to get collision.hitPosition, and collision.hitNormal

I hope collision.vector or collision.magnitude is next.

Is this in 2.73a, or will it be released in a later build?

2.74 , is what the developer meeting notes say.

Hello! Thanks for the new! And congrats to him! That’s a cool feature. I’m gonna make a new build to test it!

I wondered how you will get a point, as a collision is an intersection which … is a set of lines. But I see in the path … it returns the single result of any intersecting edge (edge intersecting face).

I do not expect much additional processing time. The single point should be sufficient enough for most of the use cases.

I wounder if the point is there average of the crossection of the intersecting planes?

Best rename the title, to be more accurate; the data is passed as arguments to the function.

So it’s not tied to a sensor?

it’s only a callback?

Can you provide usage?

syntax? Also, has anyone built a 32 bit but windows version ?

It’s in the report you linked
https://developer.blender.org/D926

hmmmm…

so a callback is only availible on polling?

can a callback change a property?

Can you provide a example of a callback, with comments ?

super simple, as I am retarted about learning new concepts, for some reason I have trouble with functions.

how hard would it be to expose this data to a sensor?
I suck at coding outside blender… without a callback?
maybe a checkbox? collision.hitPosition= None if not checked?

@BPR
I used collision callbacks for the first time this week and they are quite simple. They do work best with a class though. I’ll try to make a simple demo but classes and functions are things that you will have to use in python eventually, working without them in this case actually make things more complicated. I’ve got a good link to a tutorial about class usage if you’re interested.

I dont quite understand if callbacks fire themselves when a event happens, or are they polled and retain data?

A callback “calls back” when a condition is met. When a collision occurs, the function you append to the object’s collisions list is run.

Is there a way to acess a objects properties as a condition?

like property = “Forward”

then intiates other script? and is this before the logic step?

so the only way to acess the callback is if it has a handle?

gamobject.collisionCallback or something?

If you want that level of information, there is no point (and little ability) in exposing it via logic bricks.

what I really need is a dependable collision.localImpulse and collision.worldImpulse, I would settle for world because I could use .worldOrientation to localize.

I dont understand why it is absent, as it would be very useful for physical simulations.

When setting up your collision object you provide the code that will run if the collision happens. You don’t need to maintain that code after that, it runs itself. The code can execute an action (like end the object or add sparks and a noise at the point of collision) or it can set a property, such as on_ground = True. But the call back doesn’t do anything if it isn’t triggered, so you have to reset the property to false at the end of every frame if using callbacks to set a property or attribute:

if self.on_ground:
   ###do something
self.on_ground = False

The only “problem” with callbacks is they are pretty much autonomous. After setup you don’t deal with them again, and you can’t really change them (maybe Agoose can tell me different).

Here’s the simplest example I can think of:
collision_callbacks.blend (423 KB)

Really this is the kind of thing that collision callbacks are great at, triggering events.

You should notice three things about the blend.

  1. The sensor is not on pulse mode. It runs once and then never again, but still the event triggers. This is the essence of a collision callback. You don’t have to check it every frame (polling) just set it once when you set up the callback.

  2. The function has a special argument:

def collision(other):

Which automatically gets the other object hit. You don’t need to send that to the function. In fact you don’t need to/can’t send any optional arguments to the function. So not:

own.collisionCallbacks.append(collision(own,other))

but just:

own.collisionCallbacks.append(collision)
  1. Also, although I didn’t pass ‘own’ to the function
def collision(own,other):

It picks up a reference to ‘own’ anyway. This is handy because we can set own[‘on_ground’] or whatever, but I don’t really know how it does it. ‘own’ is not a global variable, so I don’t know how it gets in to the function.

But anyway, it works. :slight_smile:

If you had hit position and hit normal you could use them to position the spark just where you wanted it, or save them as a property on ‘own’ object.

You could get a rough idea of hit impulse by getting the linV of own and other and combining/comparing them. Math is not my strong suit though so maybe someone else could give you an idea of that, or you could find the solution online.

You can bind arguments to a function using partial, or a closure (which shares the same local namespace as the function that created it.


from functools import partial

def func(own, other):
    pass

def assign(cont):
    own = cont.owner

    own.collisionCallbacks.append(partial(func, own))


def func(own, other):
    pass

def assign(cont):
    own = cont.owner

    def wrapper(other):
        func(own, other)
 
    own.collisionCallbacks.append(wrapper)

my problem, is if I can’t cant collision.impulse,
then I have to figure whole Ik chains worth of accelerations etc.

and the collision callback sounds nice,
but what is the difference to

collision---------python ?

other then all the data is not exposed ?

why cant this data just be exposed to the sensor?

I can understand having a callback AND sensor data, but why diverge from what is?

collision.hitPosition and .hitNormal just seem more in line with the way everything works already.

If I have enough cash after taxes, I will post a bounty for
collision.impulse
collision.hitPosition
collision.hitNormal