Sign in to follow this  

How to make sure a player remains on a path.. ?

This topic is 2812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I wanna know if there is a better way to make sure a player remains on the path and does not go astray... one way to go about it would be use vectors conditions, after the x and y coordinates increase, we can check whether the new point lies within the path or not, if it doesnt, we wont increase the particular coordinate, if it lies within, well n good.. but this method will go awfully difficult when there maybe thousands of paths and curves, coding vector conditions for thousand paths might turn out to b a programming hell... the other way would be to check the color of the next pixel.. supposing the path is of white color and the so-called-not-the-path-excluding-the-wall-like-obstacles are of black color, we will check if the next pixel is black, if it is, then we wont allow the point increment, if it isnt, then increment allowed.. but this method will / might b a failure when using many colors, for black mayb the outline of any object n hence the restrictions wont allow the character to cross it especially when the character needs to be over it.. so what is d best way of making sure that a player / character remains on the path specified?? SimpleD

Share this post


Link to post
Share on other sites
no this isnt for NPCs..

its like, how / or what type of physics keeps the cars in need for speed from going into the stands n killing people.. what method do they use so that the car remains on d track.. they dont write code for every stand there is to avoid the car going into the stand, do they?

like in real life, we dont bang against the wall, we avoid it.. so in games too, we want the player to avoid every wall there is.. but coding for every wall mayb huge because there mayb thousands of walls, thousands of different codes mayb written, thousands of coordinates, thousands of "if" conditions, making program a thousand times slower..

whats a better n a simpler n a shorter way to go about it.. ?

Share this post


Link to post
Share on other sites
i've been r&ding on collision detection, but isnt collision detection d same deal.. like every time the coordinate of the player changes, we'll have to call a collision_check() function which checks whether there is a collision or not.. to check whether there is a collision, it'll has to check the collision with "all" obstacles..

is this really how every game is made? m really confused.. because its difficult to think that the developers of need for speed wrote pages actually checking whether the car rode off the rode by collision detection method..

is collision detection the answer to my query?

Share this post


Link to post
Share on other sites
Quote:
Original post by SimpleD
to check whether there is a collision, it'll has to check the collision with "all" obstacles..
...All obstacles that are spatially close. Consider using some sort of spatial partitioning system, for example: Imagine overlaying your world with a grid, if you know which grid cell(s) the car is currently occupying then you only need run the collision check with obstacles that are also in that same cell; obstacles in other cells can be safely discarded. You could divide cells into sub-cells too.

Each obstacle would probably also have its own collision volume, such as a box or sphere which is easy and cheap to check. You can very quickly and cheaply eliminate most of the obstacles in the world and only put the effort into the ones that are really close by.

Share this post


Link to post
Share on other sites
++ to what dmatter said.

Also for the case of something like a racing game, if you have a spline (bezier curve or something like it) representing the center line of the road, and you know how wide the road is, you can just check if the player is less than 1/2 the roads with from the spline. If they are, you know they are on the path, else they are off (and you can handle that case however you want to... push them back on, start ticking down a timer that makes them lose if they get to 0, or whatever you want)

Share this post


Link to post
Share on other sites
Quote:
Original post by dmatter
...All obstacles that are spatially close. Consider using some sort of spatial partitioning system, for example: Imagine overlaying your world with a grid, if you know which grid cell(s) the car is currently occupying then you only need run the collision check with obstacles that are also in that same cell; obstacles in other cells can be safely discarded. You could divide cells into sub-cells too.

Each obstacle would probably also have its own collision volume, such as a box or sphere which is easy and cheap to check. You can very quickly and cheaply eliminate most of the obstacles in the world and only put the effort into the ones that are really close by.


i'll dig into this more.. looks like this might be "the thing" thanks

Quote:
Original post by Atrix256
++ to what dmatter said.

Also for the case of something like a racing game, if you have a spline (bezier curve or something like it) representing the center line of the road, and you know how wide the road is, you can just check if the player is less than 1/2 the roads with from the spline. If they are, you know they are on the path, else they are off (and you can handle that case however you want to... push them back on, start ticking down a timer that makes them lose if they get to 0, or whatever you want)


this is indeed a very smart idea.. i'll opt for this idea till i do all the theory behind spatial partitioning system

Share this post


Link to post
Share on other sites
This is more or less a "Solved Problem". Find and integrate a 3rd party physics engine to do the collision detection for you. Trying to implement it yourself is a nightmare even if you know what you're doing; there's a reason they hire physics PHDs to make all the good physics engines.[smile]

But yes, every frame of the game the new position of all objects in the world are tested for collision and collision is handled.

plus or minus a few thousand other function calls:

while (1) //the game loop. each iteration is a frame
{
updateInput();
moveStuff();
handleCollision();
render();
}



If you really care about this topic, buy the book "Real-Time Collision Detection". It's amazing.

-me

Share this post


Link to post
Share on other sites
Yeah that book 'real time collision detection' is seriously the collision detection bible... it's amazing.

The concepts behind things is there if you are curious
The math behind things is there if you are curious
If not, the source code is there for you to copy haha

it's an amazing book

Share this post


Link to post
Share on other sites
Note that collision detection and collision avoidance are two different things, and it seems like you are looking for the latter. Collision avoidance is a steering behavior that scans the area in front of an object, and if there is an obstacle within proximity, it steers the object away from the obstacle. Google "steering behavior" and you'll find a lot of stuff about it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Palidine
This is more or less a "Solved Problem". Find and integrate a 3rd party physics engine to do the collision detection for you.


that would be for more advanced games i guess... m just starting with the simplest of all games..

Quote:
Original post by Palidine
Trying to implement it yourself is a nightmare even if you know what you're doing;


thats exactly what i was dreading..

Quote:
Original post by Palidine there's a reason they hire physics PHDs to make all the good physics engines.[smile]


i'll actually be that guy in a couple of years :P


Quote:
Original post by Palidine
But yes, every frame of the game the new position of all objects in the world are tested for collision and collision is handled.


this was some part of knowledge i was looking for.. but its a bit hard to image cuz the checking conditions would be so much.. wont it slow down the game or something??

Quote:
Original post by Palidine
plus or minus a few thousand other function calls:


snapped.


Quote:
Original post by Palidine
If you really care about this topic, buy the book "Real-Time Collision Detection". It's amazing.

-me


what i basically want in making games is to know everything there is to know, like there may b many ppl making a game, but i wanna know everything they all know.. so that in d end, i have the idea what other person is doing, n i believe it might help to optimize the code somehow.. dunno if it really would... i'll have a look at the book..


Quote:
Original post by nullsquared
Note that collision detection and collision avoidance are two different things, and it seems like you are looking for the latter. Collision avoidance is a steering behavior that scans the area in front of an object, and if there is an obstacle within proximity, it steers the object away from the obstacle. Google "steering behavior" and you'll find a lot of stuff about it.


you are very right sir.. due to lack of proper knowledge i couldnt discover collision avoidance.. so instead what i did, currently doing, is this: say our player is at point(x, y) i am checking whether the point (x+1, y) and/or the other three points collide with the paths of the walls.. a kinda checking the probability of collision in the future, the next point.. though the probability here is a set of two elements, 100% and 0%...

Share this post


Link to post
Share on other sites
what i did is when the game calls on the object, since i have objects positioned with xyz coords, like its a function, i have the collision detection in the function that draws the object. this helps with speed and you only need to code a little bit. its way more efficient but has pros and cons.

Share this post


Link to post
Share on other sites

This topic is 2812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this