Solution to PhysicalResponse bugs.

Learn how to make certain types of games and use gameEditor.

Solution to PhysicalResponse bugs.

Postby Hammerit » Thu Feb 06, 2014 12:50 pm

Solution to PhysicalResponse problems.
PhysicalResponse so easy to use so many problems to solve.
Or how to make almost perfect collision for platform game.
Problems:
1. Wall sticking - when Actor moves to the wall while jumping he will stick to it and stop falling down.
2. Glitching - when Actor hit the wall while walking on the ground he will do little jumps up and down.
3. Suicide moving - when near edge Actor will walk by himself until he fall.
4. Wall climbing - Actor will reach and climb platform even if he isn't suppose to.


Before solving this let me explain how PhysicalResponse works.
1. This event Activates when two Actors Collides.
2. PhysicalResponse calculates distance between two Actors. And put them in position where they will touch each other, changing X and Y coordinates .
But there is one problem. To calculate new position for our colliding Actors it uses ANGLES. But ANGLES always different from the ANGLE where it suppose to be. In simple word it will increase ANGLE by little and it changes position, each time when collision triggered.
Collision->PhysicalResponse->Calculates new position->Changes Angle->Changes x,y coordinates->Repositioning Actor
3. PhysicalResponse will set your colliding Actor XVELOCITY AND YVELOSIT to 0.


I should mention to move left or right i use velocity and my moving actor called HERO.

Solution:
1.Wall sticking:
Because PhysicalResponese after collision will set your YVELOSITY and XVELOSITY to 0, you should restore speed after PhysicalResponse happened.
Use this code in COLLISION LEFT OR RIGHT SIDE event.
Code: Select all
double TempYvelocity = hero.yvelocity;  //saving falling speed
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000, 1.000000, 0.000000, 0.000000);
// sets new coordinate X,Y for hero,
// sets Xvelocity,Yvelocity=0 for hero
if (HeroInTheAir == 1) // if hero is jumping or in the air, usually it is HEROCANJUMP == 0
{
   hero.yvelocity = TempYvelocity; // restore falling speed, prevents wall sticking
}

2.Glitching:
In this problem PhysicalResponse will change your Y coordinate because of that Actor glitching.
To solve this restore Y coordinate after PhyscailResponse.
Use this code in COLLISION LEFT OR RIGHT SIDE event.
Code: Select all
double TempYvelocity = hero.yvelocity; //saving falling speed
double TempYcoordinates = hero.y;      //saving Y coordinate of hero
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000, 1.000000, 0.000000, 0.000000);
// sets new coordinate X,Y for hero,
// sets Xvelocity,Yvelocity=0 for hero
hero.y = TempYcoordinates; // restore Y coordinate to prevent glitching and wall climbing
if (HeroInTheAir == 1)          // if hero is jumping or in the air, usually it is HEROCANJUMP == 0
{
   hero.yvelocity = TempYvelocity; // restore falling speed, prevents wall sticking
}

3.Suicide moving:
Because PhysicalResponse after collision will reposition your Actor changing both X and Y.
You Actor will slowly move to the end.
To solve this you can:
a) You can make yvelocity = 0 to stop collision => PhysicalResponse won't be trigert.
Because PhysicalResponse already makes Actors velocity = 0 when you collided top side, you need to restore it when you go out from ledge.
Use this code in DRAW ACTOR event.
Code: Select all
if (HeroInTheAir == 1 && hero.yvelocity < 5) // if hero is jumping or in the air and he's falling speed not greater then 5, usually it is HEROCANJUMP == 0
{
    hero.yvelocity += 0.5;
}
if (CollisionFree("hero",x,y+1) == 1)//checks if there is something under actor if not then hero is falling.
{
    HeroInTheAir = 1;
}

b) You can restore X coordinate after PhysicalResponse event.
If your hero constantly falling.
Use this code in COLLISION TOP SIDE event.
Code: Select all
if (hero.yvelocity > 0) //checks if hero falling down, it prevents blinking hero on top side of platform instead of going up.
{
    double TempXvelocity = hero.xvelocity; // saving xvelocity of hero
    double TempXcoordinates = hero.x;       // saving x coordinates of hero
    PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000, 1.000000, 0.000000, 0.000000);
    hero.x = TempXcoordinates;        //restore x coordinates
    hero.xvelocity = TempXvelocity;  //restore xvelocity speed
    HeroInTheAir = 0;
}


Code for colliding BOTTOM SIDE OF WALL. Pretty much the same except for HeroInTheAir = 0;
Code: Select all
if (hero.yvelocity < 0) //checks if hero still in jump, it prevents blinking hero on bottom side of platform instead of going down.
{
    double TempXvelocity = hero.xvelocity;
    double TempXcoordinates = hero.x;
    PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000, 1.000000, 0.000000, 0.000000);
    hero.x = TempXcoordinates;
    hero.xvelocity = TempXvelocity;
}

4.Wall climbing:
Because of constantly moving right to the wall PhysicalResponse after collision will reposition your Actor changing both X and Y coordinates.
In this problem PhysicalResponse will change your Y coordinate, so restore it after PhyscailResponse.
Use this code in COLLISION LEFT OR RIGHT SIDE event.
Code: Select all
double TempYvelocity = hero.yvelocity; //saving falling speed
double TempYcoordinates = hero.y;      //saving Y coordinate of hero
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000, 1.000000, 0.000000, 0.000000);
// sets new coordinate X,Y for hero,
// sets Xvelocity,Yvelocity=0 for hero
hero.y = TempYcoordinates; // restore Y coordinate of hero to prevent glitching and wall climbing
if (HeroInTheAir == 1)          // if hero is jumping or in the air, usually it is HEROCANJUMP == 0
{
   hero.yvelocity = TempYvelocity; // restore falling speed, prevents wall sticking
}



It will solve all bugs but:
1. It won't let you do "stair" walking any more. So use block type levels like first mario game.
2. It will glitch a little. If you fall while hugging wall, when you collide with top side of ground it will jiggle ones. (This i solved...)

Now you can do mario gap run.

And sorry for bad English it's not my native.
Attachments
when to boxes collides....png
Problems.png
Test3.zip
(229.99 KiB) Downloaded 343 times
Hammerit
 
Posts: 12
Joined: Sun Feb 02, 2014 9:52 pm
Score: 2 Give a positive score

Re: Solution to PhysicalResponse bugs.

Postby Hares » Thu Feb 06, 2014 8:55 pm

3.Suicide moving:
Because PhysicalResponse after collision will reposition your Actor changing both X and Y.
You Actor will slowly move to the end.
To solve this you can:

Awsome, you fixed suicide moving 8)

Good tutorial. Thanks for sharing.

2. It will glitch a little. If you fall while hugging wall, when you collide with top side of ground it will jiggle ones. (This i solved...)

Can you also post the solution for this? Or it is something we should figure out for ourselves ... :wink: ?
User avatar
Hares
 
Posts: 105
Joined: Fri Dec 20, 2013 8:39 pm
Location: Belgium
Score: 14 Give a positive score

Re: Solution to PhysicalResponse bugs.

Postby Hammerit » Thu Feb 06, 2014 9:15 pm

Hares wrote:
2. It will glitch a little. If you fall while hugging wall, when you collide with top side of ground it will jiggle ones. (This i solved...)

Can you also post the solution for this? Or it is something we should figure out for ourselves ... :wink: ?

To solve this:
1. Add global variable integer Hit.
2. In Collision Left or Side of ground add line.
Code: Select all
Hit = 1;

3. Add Collision Finished event with ground with code.
Code: Select all
Hit = 0;

4. Change KeyDown events to move left or right to:
For right.
Code: Select all
if (Hit  == 0)
{
 hero.xvelocity = 5;
}


It solves the problem, i'm not sure how. :D
Hammerit
 
Posts: 12
Joined: Sun Feb 02, 2014 9:52 pm
Score: 2 Give a positive score

Re: Solution to PhysicalResponse bugs.

Postby Zivouhr » Sat May 30, 2015 3:39 pm

Interesting info, thanks. Wall climbing in my first game Tomb of Twelve with the jump took some coding tricks to disable, though I'll keep this method in mind.
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Solution to PhysicalResponse bugs.

Postby nightFall16 » Sat Jun 25, 2016 7:56 pm

Awesome tut man thanks it helped me so much
User avatar
nightFall16
 
Posts: 41
Joined: Wed Jun 22, 2016 4:24 am
Score: 2 Give a positive score

Re: Solution to PhysicalResponse bugs.

Postby TDM » Sat Feb 09, 2019 5:13 am

Thank you so much mate :D
TDM
 
Posts: 7
Joined: Thu Feb 07, 2019 4:42 am
Score: 0 Give a positive score

Re: Solution to PhysicalResponse bugs.

Postby purplecloud » Sun Apr 07, 2019 6:50 am

Thank you for the awesome explanation! It helps me a lot. :)
purplecloud
 
Posts: 10
Joined: Mon Mar 12, 2018 8:00 pm
Location: Europe
Score: 1 Give a positive score


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest