Page 1 of 1

Testing collisions using Script

PostPosted: Sat Jul 18, 2009 2:41 pm
by Yaztromo
Hi, I'm a bit of a novice, what script can I use to set a condition based upon two actors colliding?

I am hoping for something like:

Code: Select all
if ("Event Actor" is colliding with "Moster12")
{
do this;
}
else
(
do another thing;
}


Hope that's clear enough. I've searched through the site and script help, but I can't find anything :x .

Re: Testing collisions using Script

PostPosted: Sat Jul 18, 2009 6:19 pm
by DST
From the actor control panel, choose events>add>collision.
IN the collision box, choose the actor, sides of actor, and repeat options.

Then for the event choose >script editor>

Then you can compare any variable you wish, using Event Actor and Collide Actor to reference the actors involved, where Event Actor is the one running the script and Collide Actor is the one it collided with.

To read simple variables from the other object, use collide.variable.

Example:

Player>collision>any Side>block>script editor>
Code: Select all
if(collide.cloneindex<10){
do something;
}

Re: Testing collisions using Script

PostPosted: Sun Jul 19, 2009 9:30 am
by Yaztromo
Thanks DST, its slightly more complicated than I explained though, what I really want to do is test whether two actors are colliding when a key is let go of (key up).

So what I have been planning to do is: Actor>Events>Key Up>Script Editor and then write the script to test whether the two actors are colliding as I outlined in my original post above.

Is there any way to do this?

Maybe I could use your way and test for 'Key Up' using Script Editor once the collision has been specified. The way I outlined above seems less work because there is only one key up event in the game, while there can be different collisions between actors, but if that can't be done, what would be an example of the script for incorporating a test for 'Key Up' using Script Editor? -Something like this?:

Code: Select all
if ('Key Up'=Key) {
if(collide.cloneindex<10){
do something;
}
}


I am sorry I didn't make it so clear before; I really thought it would be more simple than all this.

Re: Testing collisions using Script

PostPosted: Sun Jul 19, 2009 9:40 am
by DST
Use a variable for this. It will make super sense to you in a moment.

Make an actor variable in the variables tab. Here i'll call it 'colliding'.

Collision>any side>actor>
Code: Select all
colliding=1;


CollisionFinish>any side>actor>
Code: Select all
colliding=0;


Keydown>
Code: Select all
if(colliding==1){
do this;
}


now you can use the colliding variable in any script you like, it will always tell you if there's a collision.

Re: Testing collisions using Script

PostPosted: Mon Jul 20, 2009 7:38 am
by Yaztromo
Thanks very much - that should do the trick.

:P

I'll be back if it doesn't though... :roll: