Page 1 of 1

HowTo, CollisionFree?

PostPosted: Mon Jun 06, 2011 2:15 am
by RippeR7420
I'm having a hard time understanding CollisionFree. I've used the search bar and read the other forums for it but none of them seem to answer my question.

I'm trying to make it so when my MainCharacter is CollisionFree with the ground actor, His animation turns into the "Jump" animation, then goes back to the previous animation on
collision with the ground actor..

Can anybody help me figure this out please? :cry:

Re: HowTo, CollisionFree?

PostPosted: Mon Jun 06, 2011 2:57 am
by Hblade
The method you have just mentioned will result in a gltich anyways, I reccomend using something similar to this code
Code: Select all
if (yvelocity>2 || yvelocity<-2) {
    if (animindex!=4) //replace the number 4 with the jumping
                               //animation. see note 1 for more info
     {
              ChangeAnimation("Event Actor", "jump", FORWARD);
     }
}


Note 1:
You can find the animindex (animation index) by making a text actor and putting this code in it
Code: Select all
int A=player.animindex;
sprintf(text, "%d", A);

And the text actor will then tell you the animindex


Why the animindex?
this will prevent it from repeat-changing the animation that is causing that rapid animation loop.


What will this code do?
When the character is going up or down he will change to the jumping anim.

Re: HowTo, CollisionFree?

PostPosted: Mon Jun 06, 2011 3:27 am
by RippeR7420
Awesome!

+1 :D



Where should I input the codes? i.e; "Draw Actor" "Create Actor"
Thank you sooo much!

Re: HowTo, CollisionFree?

PostPosted: Mon Jun 06, 2011 4:24 am
by RippeR7420
also, my MainCharacter is like floating above the ground actor?

Thanks again :)

Re: HowTo, CollisionFree?

PostPosted: Mon Jun 06, 2011 5:11 am
by jimmynewguy
draw actor. And you can get rid of the second if by stating no change instead of forward

Code: Select all
if (yvelocity>2 || yvelocity<-2)
{
ChangeAnimation("Event Actor", "jump", NO_CHANGE);
}


and just so you understand for future needs, you use collision free with the first variable being in quotes the name of the actor you are checking, then a comma and the x value, then a comma and the y value. That's sorta a weird way of explaining it though... the documentation says:

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.


it has all script references, in GE go to the top right of the task bar choose help -> documentation -> scripting -> scroll to the bottom and click script refrence

Re: HowTo, CollisionFree?

PostPosted: Mon Jun 06, 2011 3:33 pm
by RippeR7420
+1 JimmyNewGuy :)

Re: HowTo, CollisionFree?

PostPosted: Mon Jun 06, 2011 7:57 pm
by Hblade
JNG: I had no idea about that! :D Thanks!

Re: HowTo, CollisionFree?

PostPosted: Mon Jun 06, 2011 9:06 pm
by lcl
Hblade, there is easier ways to find out the animindex.
No need to check anything by yourself, just use getAnimIndex(); and let it be done for you!

Example:
Code: Select all
if (animindex == getAnimIndex("myAnimation"))
{
    //here comes the action
}

That was just in case you weren't familiar with getAnimIndex(); already. :D

Re: HowTo, CollisionFree?

PostPosted: Tue Jun 07, 2011 1:32 pm
by jimmynewguy
No problem. But just to warn everyone, makslane taught me about getanimindex(); and told me not to use it too often due to it's slowness. Don't know if that still applies so I tend to avoid that function.

For the animindex, the first animation in the list for the actor is 0, then it just increases by one as you go down. So there really shouldn't be the need for a way to figure it out, or for getanimindex(); here if you know what it is already :D