Page 1 of 1

Actor Collisions Question

PostPosted: Thu Apr 26, 2012 12:11 pm
by banny94
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?

Re: Actor Collisions Question

PostPosted: Thu Apr 26, 2012 1:43 pm
by skydereign
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

Re: Actor Collisions Question

PostPosted: Thu Apr 26, 2012 2:14 pm
by banny94
Cheers buddy, big help! :)

Re: Actor Collisions Question

PostPosted: Thu Apr 26, 2012 3:25 pm
by banny94
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.

Re: Actor Collisions Question

PostPosted: Thu Apr 26, 2012 3:51 pm
by skydereign
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).

Re: Actor Collisions Question

PostPosted: Thu Apr 26, 2012 4:04 pm
by banny94
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?

Re: Actor Collisions Question

PostPosted: Thu Apr 26, 2012 4:19 pm
by skydereign
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?

Re: Actor Collisions Question

PostPosted: Thu Apr 26, 2012 7:24 pm
by banny94
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.