Page 1 of 1

Collision State

PostPosted: Fri Jul 15, 2011 2:36 pm
by foleyjo
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?

Re: Collision State

PostPosted: Fri Jul 15, 2011 4:14 pm
by foleyjo
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.

Re: Collision State

PostPosted: Sat Jul 16, 2011 2:08 pm
by Camper1995
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?)

Re: Collision State

PostPosted: Sat Jul 16, 2011 4:06 pm
by foleyjo
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.

Re: Collision State

PostPosted: Sat Jul 16, 2011 6:01 pm
by Camper1995
Yes, it helped. Thank you. +1 :P