More informations about collided object

If there is something important you think is missing in the current version of ZGameEditor then you can post a feature request here!

Moderator: Moderators

Post Reply
kattle87
Posts: 402
Joined: Wed Sep 26, 2007 9:06 am
Location: Italy

More informations about collided object

Post by kattle87 »

Is there any way to get more infos about the object you collided with?
An idea could be: in ZExpression, one could use the keyword "this" for referring the current model, and a different keyword like "collided" for referring to the other model.

By doing this, one could be sure about position, speed, and so on.
EG: something like

DistanceOnX = this.Position.X - collided.Position.X;

Is it possible to do something like that?
User avatar
Kjell
Posts: 1879
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Francesco,

The problem with something like a Collided. reference for ZExpression is that this won't be any good when you could have multiple collisions occurring at the same time. Even the current Category approach is a little limiting as there is a maximum of 32. So giving each instance their own Collision category is only a option when you never need more then 32 instances that utilize collision.

This is the work-around that I currently use. Give all models that cause the same behavior on models they collide with the same collision category. Then for each collision category that you want to collect information of, I create a RenderTransform component which I name appropriately. Then figure out if there are any categories that need support for multiple simultaneous collisions. For those categories create a counter and the appropriate amount of extra RenderTransform components to collect data of those instances. Then on collision let instances pass their data to the RenderTranform according component, which can then be collected by whoever needs it. Make sure to spawn your objects in a order that makes sense ( static objects first ).

It's quite a bit of hassle, but with this approach you can even create all the collision behavior you'd need for a 3d action or platforming game ( using the X/Y as floor, and Z as up due to Rect2D_OBB ).

*I even previously claimed that slopes would not be possible, but using this method it's actually not all that difficult. Attached is a example. Use Arrow Keys to Move, A/D to rotate the camera.

Good luck,
K
Attachments
Slopes.zip
(37.79 KiB) Downloaded 513 times
kattle87
Posts: 402
Joined: Wed Sep 26, 2007 9:06 am
Location: Italy

Post by kattle87 »

ok I have not get how do you do that. I suppose I have some english-related problems or stuff like that :P however, it is not important.

The thing I would like to do is the following: given N balls (N = number of balls) when they collide each other, calculate the "collision point" (the midpoint between the centers of the 2 balls). And I would like to avoid using 32 different collision categories as I would like "clone" for ball spawn.
If one was able to use "collided" that would be really easy.
The multiple collisions are not a big problem, because the collided. reference would change like the App.CollidedCategory does...

More: you can always keep the App.CollidedCategory alive for backward compatibility...

PS: :) Maybe I have not understood your objection :)
User avatar
Kjell
Posts: 1879
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Francesco,

I understand what you're asking for, but that method won't cut it as soon as there will be multiple collisions occurring on one instance. I've attached a image illustrating such a situation. If you'd have a ZExpression on the Pink Sphere using Collided.Position.X .. would it have to return -1 ( Aqua ) or 1 ( Yellow )?

K
Attachments
Spheres.jpg
Spheres.jpg (30.44 KiB) Viewed 10630 times
kattle87
Posts: 402
Joined: Wed Sep 26, 2007 9:06 am
Location: Italy

Post by kattle87 »

when you are in the same situation using App.CollidedCategory, how does current collision works?

Prove me wrong, but you should get 2 collisions: OnCollision is called twice, one time with App.CollidedCategory = "Category of Yellow" and the other time with App.CollidedCategory = "Category of Cyan".

It should work the exact way: You get two collisions (OnCollided should be called twice) and everytime the collided. reference is different.

PS: I might be wrong but I don't think so :D
User avatar
Kjell
Posts: 1879
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Francesco,

Ah like that :) Ok, I guess you can just cache all of the Collision values ( + count the amount of Collisions occured ) and calculate the appropriate behavior from all those together afterwards in OnUpdate then. You probably still want to use a component like RenderTranform to easily store all the values in though .. but this would make it a little easier yes.

Would be nice if you could choose a Variable type ( Vector, Matrix ) in the DefineVariable component actually :roll:

K
kattle87
Posts: 402
Joined: Wed Sep 26, 2007 9:06 am
Location: Italy

Post by kattle87 »

Really I don't get how you want to use RenderTranform to easily store all the values... Can it be used as a push/pop instruction?????
User avatar
Kjell
Posts: 1879
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hey Francesco,

That's the way I use it yes. It doesn't work automatically obviously, you'll have to store which rows / RenderTransformGroups are occupied by which Clones ( each get their own ID OnSpawn ) yourself. But I find it much more convenient then having to define a Float for each variable that you want to push around ( since it's 9 variables per component ). Even though I might loose some CPU time from the execution of those components ( not sure if they check whether they are empty or not ).

K
kattle87
Posts: 402
Joined: Wed Sep 26, 2007 9:06 am
Location: Italy

Post by kattle87 »

well, I will enjoying taking a look at the code :P When you want, feel free to post it (would fit nice under tips&tricks i think) Not a high priority however... bye bye :)
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

cool idea!

Post by jph_wacheski »

Francesco - indeed that is an issue that has been troubleing me as well,.

Kjell - wow that is neet! I am trying to understand what you are describing,. and I think i kinda' get you,. however I would also lov to see a small example .zgeproj just of how you are passing the values and sorting the instances that touch. No big rush,. just whenever you get around to it, as I would not want to take you away from the joystick implementation ;) ! I am really looking forward to that one!!! peace.
iterationGAMES.com
Post Reply