Actor Collisions Question

Non-platform specific questions.

Actor Collisions Question

Postby banny94 » Thu Apr 26, 2012 12:11 pm

Hi, i'm creating a game for my college coursework and i did have a method to make the actor stop when it collides with the map outline i created, however i have since not been able to re-create this. As far as i'm aware i used the CollisionFree function but can't remember how this function works and what variables to enter. Can somebody help me please?
banny94
 
Posts: 5
Joined: Thu Apr 26, 2012 12:04 pm
Score: 0 Give a positive score

Re: Actor Collisions Question

Postby skydereign » Thu Apr 26, 2012 1:43 pm

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.

If you ever need to look up a gE function, you should check the script reference. http://game-editor.com/docs/script_reference.htm
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Actor Collisions Question

Postby banny94 » Thu Apr 26, 2012 2:14 pm

Cheers buddy, big help! :)
banny94
 
Posts: 5
Joined: Thu Apr 26, 2012 12:04 pm
Score: 0 Give a positive score

Re: Actor Collisions Question

Postby banny94 » Thu Apr 26, 2012 3:25 pm

if(CollisionFree("kid", x, y))
{
yvelocity=-5;
view.yvelocity=-5;
}
ChangeAnimation("kid", "Game - User Still Vertical", FORWARD);

this is the code i tried to use as a tester to make the view + actor go forward, however it doesn't move at all. Could anyone inform me where i may have gone wrong? thanks.
banny94
 
Posts: 5
Joined: Thu Apr 26, 2012 12:04 pm
Score: 0 Give a positive score

Re: Actor Collisions Question

Postby skydereign » Thu Apr 26, 2012 3:51 pm

First question, is "kid" "Event Actor"? If so, I suggest you replace that. Are you sure that the actor is free of collisions? If you have a filled region, or any other actor then CollisionFree will return false. If "Event Actor" and "kid" are not the same actor, then unless the event actor is invisible the collision free will always return false (since at position xy kid would collide with event actor).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Actor Collisions Question

Postby banny94 » Thu Apr 26, 2012 4:04 pm

I guess that would be the case yeah, it's the kid who is the controlled character, i'm relatively new to GE so a lot of the jargon is alien to me, but all i know is i have used several actors and the outline of the map + floor are created using actors, would they be better off as something different?
banny94
 
Posts: 5
Joined: Thu Apr 26, 2012 12:04 pm
Score: 0 Give a positive score

Re: Actor Collisions Question

Postby skydereign » Thu Apr 26, 2012 4:19 pm

One very important thing to know is "Event Actor", as it specifies the actor that owns the actual event. So if you want a keydown event to change the actor's animation, you can use ChangeAnimation and use for the actor name "Event Actor".

The CollisionFree function returns true if the actor is not colliding if moved to the position xy. So the only reason your actor isn't falling is if that event isn't being triggered, or the actor is colliding with something. Without seeing the file, I can't tell you which it is, but it should be pretty easy to tell. Is the kid actor colliding with any other actor when you start the game?
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Actor Collisions Question

Postby banny94 » Thu Apr 26, 2012 7:24 pm

yeah i have an actor called Carpet which is the ground design for it to walk across, with the walls being the only thing i want it to collide with and not go straight through.
banny94
 
Posts: 5
Joined: Thu Apr 26, 2012 12:04 pm
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest