Testing collisions using Script

Non-platform specific questions.

Testing collisions using Script

Postby Yaztromo » Sat Jul 18, 2009 2:41 pm

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 .
Yaztromo
 
Posts: 3
Joined: Fri Nov 21, 2008 6:28 am
Score: 0 Give a positive score

Re: Testing collisions using Script

Postby DST » Sat Jul 18, 2009 6:19 pm

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;
}
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Testing collisions using Script

Postby Yaztromo » Sun Jul 19, 2009 9:30 am

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.
Yaztromo
 
Posts: 3
Joined: Fri Nov 21, 2008 6:28 am
Score: 0 Give a positive score

Re: Testing collisions using Script

Postby DST » Sun Jul 19, 2009 9:40 am

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.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Testing collisions using Script

Postby Yaztromo » Mon Jul 20, 2009 7:38 am

Thanks very much - that should do the trick.

:P

I'll be back if it doesn't though... :roll:
Yaztromo
 
Posts: 3
Joined: Fri Nov 21, 2008 6:28 am
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron