Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Getting Started

if sensor A collision 2 other sensors(M and N)  [SOLVED]

You feel lost? You don't understand how to use ShiVa?

if sensor A collision 2 other sensors(M and N)

Postby Simon » 20 Apr 2012, 09:50

Greetings
i have 3 objects : A(atached sensor1 ) B(sensor2) C(sensor3)


- how to get handler of B and C, if sensor1 has collision with sensor2 and sensor 3 at the same time
User avatar
Simon
Expert Boarder
Expert Boarder
 
Posts: 112
Location: Russia, Siberia

Re: if sensor A collision 2 other sensors(M and N)

Postby broozar » 20 Apr 2012, 10:15

you need to work with IDs. assign those IDs either with code or in the editor itself. then, capture the event using

Code: Select all
onSensorCollision ( nSensorID, hTargetObject, nTargetSensorID )


Code: Select all
if nTargetSensorID == 1 then --and 2, 3, etc
--code
end
User avatar
broozar
Platinum Boarder
Platinum Boarder
 
Posts: 3595
Location: Berlin - Germany

Re: if sensor A collision 2 other sensors(M and N)

Postby Simon » 20 Apr 2012, 10:44

'nSensorID ' - ID of the sensor of the current object which has been hit
'hTargetObject ' - The other hit object
'nTargetSensorID ' - ID of the sensor of the other hit object


object A has only one sensor with ID=0
objects A nd C also
User avatar
Simon
Expert Boarder
Expert Boarder
 
Posts: 112
Location: Russia, Siberia

Re: if sensor A collision 2 other sensors(M and N)

Postby broozar » 20 Apr 2012, 10:48

yes, but you can change that! and then work with the target sensor ID too. just assign other sensor IDs to object B and C than 0.
alternatively, you can work with hTargetObject...
User avatar
broozar
Platinum Boarder
Platinum Boarder
 
Posts: 3595
Location: Berlin - Germany

Re: if sensor A collision 2 other sensors(M and N)

Postby Simon » 20 Apr 2012, 11:00

thank you i try it. (but i think it will not work :( )

another question:
and can be detected collision between 2 sensors not using onSensorCollision Event. i want detect it inside code. it need me because i will create sensor to object without own AI.
User avatar
Simon
Expert Boarder
Expert Boarder
 
Posts: 112
Location: Russia, Siberia

Re: if sensor A collision 2 other sensors(M and N)

Postby broozar » 20 Apr 2012, 11:40

well, adding an AI to an object is super simple, even in code.

http://www.stonetrip.com/developer/doc/api/object-addAIModel

if for whatever reason you cannot use AI models, you will have to revert to the "old" (pre-1995) method of comparing object distances using http://www.stonetrip.com/developer/doc/api/object-getDistanceToObject. but you will have to do that for every object, and for every frame. it would be incredibly time consuming and suck a lot of processing power. just don't. add an ai model via code and you are set.
User avatar
broozar
Platinum Boarder
Platinum Boarder
 
Posts: 3595
Location: Berlin - Germany

Re: if sensor A collision 2 other sensors(M and N)

Postby Simon » 20 Apr 2012, 11:42

broozar wrote:yes, but you can change that! and then work with the target sensor ID too. just assign other sensor IDs to object B and C than 0.
alternatively, you can work with hTargetObject...


at the same time "target sensor ID" can show only one target sensor...i need to get all sensors that intersects with sensormain from AIsensorMain :(
User avatar
Simon
Expert Boarder
Expert Boarder
 
Posts: 112
Location: Russia, Siberia

Re: if sensor A collision 2 other sensors(M and N)

Postby Simon » 20 Apr 2012, 12:07

or i need from "AI sensor1" and from "AI sensor2" and from "AI sensor3" send event to "mainsensorAI" that they has intersection with "mainsensorAI"?
User avatar
Simon
Expert Boarder
Expert Boarder
 
Posts: 112
Location: Russia, Siberia

Re: if sensor A collision 2 other sensors(M and N)  [SOLVED]

Postby broozar » 20 Apr 2012, 12:11

i have written you a small test program. as you can see, the middle box collides with bot the left and the right box, and i get 2 collision events in the log for box 2, while for box 1 and 3 only 1 event gets returned.

Code: Select all
[o Message ] {Scripting         }sensortest2_box (1)
[o Message ] {Scripting         }has collided with sensor 1
[o Message ] {Scripting         }sensortest2_box (2)
[o Message ] {Scripting         }has collided with sensor 0
[o Message ] {Scripting         }sensortest2_box (2)
[o Message ] {Scripting         }has collided with sensor 2
[o Message ] {Scripting         }sensortest2_box (3)
[o Message ] {Scripting         }has collided with sensor 1


here's the project, http://www.stonetrip.com/developer/dump/sensortest2.ste let me know if this helps.

note how every box has exactly the same AI model, they only differ in the sensor ID that i have assigned to the boxes in the scene (not the model view!).


in your case (picture above), your main sensor would be my middle box in my example. using the target sensor ID, you can easily detect which box hit the main sensor, and it does not matter whether you have on, two, or more intersection events.
User avatar
broozar
Platinum Boarder
Platinum Boarder
 
Posts: 3595
Location: Berlin - Germany

Re: if sensor A collision 2 other sensors(M and N)

Postby Simon » 20 Apr 2012, 12:36

i do not know how :idea: , but it works :shock: :shock: :shock: :D

function sensortest2_boxai.onSensorCollisionBegin ( nSensorID, hTargetObject, nTargetSensorID )
--------------------------------------------------------------------------------

if (hTargetObject and nSensorID==1) then

log.message ( nTargetSensorID )
end

--------------------------------------------------------------------------------
end

it show me

0
2
0
2
.....


I am very grateful to you :D
User avatar
Simon
Expert Boarder
Expert Boarder
 
Posts: 112
Location: Russia, Siberia


Return to Getting Started