Collision State

Non-platform specific questions.

Collision State

Postby foleyjo » Fri Jul 15, 2011 2:36 pm

Is it possible to turn off the collision state between 2 actors only leaving them free to collide with everything else.

The reason I ask is because I'm using the CollisionFree("Event Actor",x,y) which is working fine except there is 1 actor that sometimes collides and I don't want it included in the check. I have tried turning the collision state to disabled for this actor but it sometimes needs to collide with other objects.

Is it possible to say

Code: Select all
if CollisionFree("Event Actor,x,y) && !Collide.ignore 


with ignore being an actor variable set to 1 if it's the one to be ignored?
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Collision State

Postby foleyjo » Fri Jul 15, 2011 4:14 pm

OK I think I got a solution.

Not sure if it's the best solution but just before the check I change the collision state of the ignored actor to disabled.
Run the check
Re-enable the collision state of the ignored actor.

This is done in the draw function so it's constantly changing the state.
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Collision State

Postby Camper1995 » Sat Jul 16, 2011 2:08 pm

Hey, this question will be a bit offtopic, but can you shortly explain me how to use it instead
of physical response? I'd like to learn thins CollisionFree usage. Yeah, I know the syntaxe but still,
it's a bit hard to define it for all 4 direction ways of actor, right?

Thanks

(or can you just post the data of your game or whatever you are working on so I can look at the code and learn something new?)
Say hello to my little friend.
User avatar
Camper1995
 
Posts: 707
Joined: Tue Dec 30, 2008 7:20 pm
Location: Lost in the past.
Score: 44 Give a positive score

Re: Collision State

Postby foleyjo » Sat Jul 16, 2011 4:06 pm

To define it for all 4 directions I think you would need 4 different collision free commands for each direction you are checking

For what I'm doing I only needed to check below the player to make sure there was something to walk on. To do this I used
if(CollisionFree("Event Actor",x,y+2))

So I'm checking to make sure there is no collision at the point 2 below the event actor.

In my code I have the player in different states. 2 of these are Walking and Falling

In the Walking State the player is able to walk as long as there is a platform underneath. When there is no platform the state changes to falling. When falling the players yvelocity is increased until there is a collision with a platform. This is done with a simple collision action with the platform which causes the yvelocity to = 0 and the state to go back to walking.

So my collision free section is simply

if(CollisionFree("Event Actor",x,y+2))
state = falling;


I will be posting the whole game sometime in the next couple of weeks. Just need to add all the enemy sprites and some kind of start and ending. However I can post the whole code for the section where I use the collisionfree command.

Code: Select all
//In the draw Actor Action
char* key = GetKeyState();

switch (State)
{
  case 1:  //Walking
    xspeed = (key[KEY_RIGHT] - key[KEY_LEFT]) * 5;
    if (xspeed)
      ChangeAnimationDirection("PlayerWan", FORWARD);
    else
      ChangeAnimationDirection("PlayerWan", STOPPED);
    if ((xspeed > 0 && !WallRight)||(xspeed < 0 && !WallLeft))
      x+= xspeed;
    if(xspeed > 0 && PlayerWan.animindex !=0) ChangeAnimation("PlayerWan", "WanWalkRight", NO_CHANGE);
    if(xspeed < 0 && PlayerWan.animindex !=1) ChangeAnimation("PlayerWan", "WanWalkLeft", NO_CHANGE);
    if(xspeed == 0 && PlayerWan.animindex ==0 ) ChangeAnimation("PlayerWan", "WanFaceRight", NO_CHANGE);
    if(xspeed == 0 &&PlayerWan.animindex ==1 ) ChangeAnimation("PlayerWan", "WanFaceLeft", NO_CHANGE);


    CollisionState("PlayerWan", DISABLE);
    if(CollisionFree("Event Actor",x,y+2))
      State =2;
    CollisionState("PlayerWan", ENABLE);
    if (key[KEY_SPACE])
    {
      yvelocity -= 14;
      State = Jumping
    }
  break;
  case 2:  //Falling
    yvelocity++;
  break;
  case 3:  //Jumping
    if (yvelocity <18)
      yvelocity+=1;
     if ((xspeed > 0 && !WallRight)||(xspeed < 0 && !WallLeft))
      x+= xspeed;
    if(xspeed > 0)
    {  if (PlayerWan.animindex !=0) ChangeAnimation("PlayerWan", "WanWalkRight", NO_CHANGE);
        PlayerWan.animpos =1;
    }
    if(xspeed < 0)
    {
      if(PlayerWan.animindex !=1) ChangeAnimation("PlayerWan", "WanWalkLeft", NO_CHANGE);
        ChangeAnimation("PlayerWan", "WanWalkLeft", NO_CHANGE);
      PlayerWan.animpos =6;
    }
 
    ChangeAnimationDirection("PlayerWan", STOPPED);
  break;
  case 4: //dying
    if (PlayerWan.lives <= 0)
    {  State = Dead;}
    else
    {
      RestartIn--;
      if (RestartIn<=0)
      {
       CollisionState("Event Actor", ENABLE);
       CollisionState("PlayerWan", ENABLE);
       x = checkpointx;
       y = checkpointy;
       yvelocity = 0;
       State = Walking;
       ChangeAnimation("PlayerWan", "WanFaceLeft", FORWARD);
      }
    }
  break;
  case 5:
    RestartIn--;
    if (RestartIn<=0)
      LoadGame("WanDed.ged");
  break;
}


Hope this helps.
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Collision State

Postby Camper1995 » Sat Jul 16, 2011 6:01 pm

Yes, it helped. Thank you. +1 :P
Say hello to my little friend.
User avatar
Camper1995
 
Posts: 707
Joined: Tue Dec 30, 2008 7:20 pm
Location: Lost in the past.
Score: 44 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest