Page 1 of 1

Actor stop at wall

PostPosted: Mon Apr 23, 2012 9:31 pm
by phyzix5761
What is the best way to make an actor stop when hitting a wall? But, also being able to retain the ability to move in the opposite direction. I've tried a few solutions but the best one I've come up with is to push the actor x amount of pixels backwards. This creates an earthquake type motion when the view is following the actor and it's unpleasant. Any other solutions out there?

Thanks guys.

Re: Actor stop at wall

PostPosted: Mon Apr 23, 2012 10:17 pm
by skydereign
What I usually do is create a bounding box actor that handles movement and collisions. The player is parented to that. The actual collisions are standard PhysicalResponse, with x or yvelocity conserving depending on what direction of collision (top/bottom or left/right).

Re: Actor stop at wall

PostPosted: Tue Apr 24, 2012 12:00 am
by phyzix5761
what do you mean x or y velocity conserving? Also, When I try to use physical response the screen vibrates a bit. I have set it to 0.0,0.0 for the last two parameters.

Re: Actor stop at wall

PostPosted: Tue Apr 24, 2012 1:00 am
by skydereign
Screen vibrating is probably because of how you do view control. But as for conserving xvelocity/yvelocity, that is just overcoming the problem where the player can stick to walls.
Code: Select all
double yvel = yvelocity;
// PhysicalResponse
yvelocity = yvel;

PhysicalResponse when setting the last two to zero, will set the actor's xvelocity and yvelocity to 0. This means the actor will stop falling. But in that code it creates a local variable that saves what yvelocity was, and after the PhysicalResponse, sets it back to what it was (conserving yvelocity).

Re: Actor stop at wall

PostPosted: Tue Apr 24, 2012 12:46 pm
by foleyjo
As an alternative if yoour using the x+= var method of moving in the collision with the wall you set a variable named NotWall to 0 and in the collision finish set NotWall to 1

Now in your movement script whereever it lies use x+= var *NotWall .

Re: Actor stop at wall

PostPosted: Tue Apr 24, 2012 4:34 pm
by Game A Gogo
Most people around these forum get used to a bad concept of collision, which is:
Move actor then check if it's colliding with something

The best concept to approach around collision is:
Check if there is no collision towards where the player wants to be, THEN move actor if there is no collision

Although I understand that physical response doesn't allow this to happen so you have to write your own collision system if you want to use the right concept

EDIT:
A way I suppose might work for less advanced scripter is Move the player to where you want it to be, check if it's colliding with something, if it is, move it back, otherwise leave it where it is. This uses more CPU than the right concept, but gives the same result

Re: Actor stop at wall

PostPosted: Tue Apr 24, 2012 4:55 pm
by skydereign
The problem I have with checking before moving is that you have to disable the collision states of all other actors that might be on the screen, which I often want to use in other collisions. Actually using the collision event allows to target individual actors. It might be possible to write CollisionFree2(char* actor, double x, double y, char* actor_arg_list, ...), which could bypass this problem, I'd have to take a look first. Also for actors that are simply moving (by velocity for instance) there is no way of checking if they are going to collide.

Re: Actor stop at wall

PostPosted: Tue Apr 24, 2012 6:08 pm
by Game A Gogo
The thing with collision is you have to go forward in time and back in time all the time :)
So with moving actors, like a bullet, you simply move it forward and back by it's velocity times the amount of time you move in time.

But I'd agree Game Editor makes it hard to apply this concept, because it breaks up completely the concept of Control->Update->Draw

EDIT: as for checking collision towards where you are moving, I've made an example of this in my perfect collision example, though it collides with everything yes, but if you create several actors and move them with the velocity of the main actor, you can effectively check all the colliding object and do action according to which had been colliding. I've used this in my latest Jason's World example. But game editor makes it buggy sometimes because of how it does the Control, update and draw all over the place