Actor stop at wall

Game Editor comments and discussion.

Actor stop at wall

Postby phyzix5761 » Mon Apr 23, 2012 9:31 pm

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.
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

Re: Actor stop at wall

Postby skydereign » Mon Apr 23, 2012 10:17 pm

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).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Actor stop at wall

Postby phyzix5761 » Tue Apr 24, 2012 12:00 am

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.
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

Re: Actor stop at wall

Postby skydereign » Tue Apr 24, 2012 1:00 am

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).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Actor stop at wall

Postby foleyjo » Tue Apr 24, 2012 12:46 pm

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 .
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Actor stop at wall

Postby Game A Gogo » Tue Apr 24, 2012 4:34 pm

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
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Actor stop at wall

Postby skydereign » Tue Apr 24, 2012 4:55 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Actor stop at wall

Postby Game A Gogo » Tue Apr 24, 2012 6:08 pm

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
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron