Page 1 of 1

Collision Detection, and location Detection

PostPosted: Sun Jan 15, 2012 2:31 am
by raminkhan
is there anyway in GE to check for a objects location and check whether or not if it has collided or not?

Re: Collision Detection, and location Detection

PostPosted: Sun Jan 15, 2012 3:38 am
by Fojam
you can create a collision event and set it to collision with "any object". then set the action in script editor, create a variable called isColliding, and set it to 1 in the script. then close the script and make a collision finish event. set it as collision finish with "any object" and set the action as script editor. Then in the script, set isColliding to 0 . now whenever you want to check if that object is colliding with something, write:
Code: Select all
if(isColliding==1)
{
    //do whatever
}

Re: Collision Detection, and location Detection

PostPosted: Sun Jan 15, 2012 2:36 pm
by Game A Gogo
Using the CollisionFree function should be more useful
Here's how to use it from the documentation:
CollisionFree: Check if position (x, y) is collision free for ActorName. Return 1 if not collide, 0 otherwise.
int CollisionFree(char *actorName, int x, int y)
Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Parent Actor": Event Actor's parent, if exists.
- "Creator Actor": Event Actor's creator, if Event Actor has been created in some "Create Actor" action.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.


Script Editor Syntax:
if (CollisionFree("Event Actor", x, y+5)) y=y+5; //On KeyDown Event script for KEY_DOWN, check if there is no collision before moving an actor down by 5 pixels.

Re: Collision Detection, and location Detection

PostPosted: Sun Jan 15, 2012 5:08 pm
by Fojam
GaG you are a programming god