Collision Detection, and location Detection

Non-platform specific questions.

Collision Detection, and location Detection

Postby raminkhan » Sun Jan 15, 2012 2:31 am

is there anyway in GE to check for a objects location and check whether or not if it has collided or not?
raminkhan
 
Posts: 63
Joined: Mon Sep 12, 2011 3:35 pm
Score: 0 Give a positive score

Re: Collision Detection, and location Detection

Postby Fojam » Sun Jan 15, 2012 3:38 am

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
}
CLICK TO GIVE ME POINTS

My Latest Projects:
Super Smash Bros: viewtopic.php?f=6&t=12307 PLEASE help by making sprites!
User avatar
Fojam
 
Posts: 513
Joined: Thu Mar 19, 2009 10:02 pm
Location: under your bed!!!
Score: 69 Give a positive score

Re: Collision Detection, and location Detection

Postby Game A Gogo » Sun Jan 15, 2012 2:36 pm

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.
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Collision Detection, and location Detection

Postby Fojam » Sun Jan 15, 2012 5:08 pm

GaG you are a programming god
CLICK TO GIVE ME POINTS

My Latest Projects:
Super Smash Bros: viewtopic.php?f=6&t=12307 PLEASE help by making sprites!
User avatar
Fojam
 
Posts: 513
Joined: Thu Mar 19, 2009 10:02 pm
Location: under your bed!!!
Score: 69 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest