HowTo, CollisionFree?

Game Editor comments and discussion.

HowTo, CollisionFree?

Postby RippeR7420 » Mon Jun 06, 2011 2:15 am

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:
CURRENT PROJECTS:

-Olo: The Sword Shaman http://game-editor.com/forum/viewtopic.php?f=4&t=12919

-The Wrath of Blob: (On the back burner)

-StickMcGee - Blast to the Future http://game-editor.com/forum/viewtopic.php?f=4&t=13660
User avatar
RippeR7420
 
Posts: 391
Joined: Mon Apr 27, 2009 4:16 pm
Location: Salt Lake City, Utah.
Score: 23 Give a positive score

Re: HowTo, CollisionFree?

Postby Hblade » Mon Jun 06, 2011 2:57 am

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.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: HowTo, CollisionFree?

Postby RippeR7420 » Mon Jun 06, 2011 3:27 am

Awesome!

+1 :D



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

-Olo: The Sword Shaman http://game-editor.com/forum/viewtopic.php?f=4&t=12919

-The Wrath of Blob: (On the back burner)

-StickMcGee - Blast to the Future http://game-editor.com/forum/viewtopic.php?f=4&t=13660
User avatar
RippeR7420
 
Posts: 391
Joined: Mon Apr 27, 2009 4:16 pm
Location: Salt Lake City, Utah.
Score: 23 Give a positive score

Re: HowTo, CollisionFree?

Postby RippeR7420 » Mon Jun 06, 2011 4:24 am

also, my MainCharacter is like floating above the ground actor?

Thanks again :)
CURRENT PROJECTS:

-Olo: The Sword Shaman http://game-editor.com/forum/viewtopic.php?f=4&t=12919

-The Wrath of Blob: (On the back burner)

-StickMcGee - Blast to the Future http://game-editor.com/forum/viewtopic.php?f=4&t=13660
User avatar
RippeR7420
 
Posts: 391
Joined: Mon Apr 27, 2009 4:16 pm
Location: Salt Lake City, Utah.
Score: 23 Give a positive score

Re: HowTo, CollisionFree?

Postby jimmynewguy » Mon Jun 06, 2011 5:11 am

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
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: HowTo, CollisionFree?

Postby RippeR7420 » Mon Jun 06, 2011 3:33 pm

+1 JimmyNewGuy :)
CURRENT PROJECTS:

-Olo: The Sword Shaman http://game-editor.com/forum/viewtopic.php?f=4&t=12919

-The Wrath of Blob: (On the back burner)

-StickMcGee - Blast to the Future http://game-editor.com/forum/viewtopic.php?f=4&t=13660
User avatar
RippeR7420
 
Posts: 391
Joined: Mon Apr 27, 2009 4:16 pm
Location: Salt Lake City, Utah.
Score: 23 Give a positive score

Re: HowTo, CollisionFree?

Postby Hblade » Mon Jun 06, 2011 7:57 pm

JNG: I had no idea about that! :D Thanks!
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: HowTo, CollisionFree?

Postby lcl » Mon Jun 06, 2011 9:06 pm

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
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: HowTo, CollisionFree?

Postby jimmynewguy » Tue Jun 07, 2011 1:32 pm

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
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron