• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
tom_mai78101

Double Collision Responses on same Object executing in order: How to fix it?

8 posts in this topic

Here's a diagram depicting what I meant as "double collision response":

[img]http://i1207.photobucket.com/albums/bb464/tom_mai78101/Untitled-7.png[/img]

I have in my code a way to work out the collision responses. It resolves the object from being inside the designated collision area by pushing the object outward in correlation to the speed vector.

The code works for 2 objects colliding each other, but never more than 2. There are some cases, apparently becoming frequent, that involves an object colliding with other two objects at the same time.

When that happens, the collision detection executes linearly. In other words, it executes the collision detection one by one. The top of the funnel is always the first to calculate the collision detection and its response to the object. After calculation, it's the bottom collision detection's turn. I see the variables while debugging change rapidly and offcourse, which causes the object itself to get pushed up and down. I think the culprit is the order of execution, where the [color=#FF0000]first collision response of the first collision area [/color]made the object move away and towards the [color=#0000FF]second collision area.[/color]

[color=#0000FF]The second collision response of the second collision area[/color] made the object move away and towards the [color=#FF0000]first collision area[/color]. This continues in a tight game loop, which upon viewing, it would look like the object is moving up and down rapidly.

[b]Does anyone know how to fix this? Thanks![/b]



The code in question is here: (2 objects collision response)

[source lang="java"]public void resolveCollision(Ball b) {
float xVelocity = this.speed[0] - b.speed[0];
float yVelocity = this.speed[1] - b.speed[1];
float xDist = this.position[0] - b.position[0];
float yDist = this.position[1] - b.position[1];
float dotProduct = xDist * xVelocity + yDist * yVelocity;
if (dotProduct > 0) {
float distSquared = xDist * xDist + yDist * yDist;
float collisionScale = dotProduct / distSquared;
float xCollision = xDist * collisionScale;
float yCollision = yDist * collisionScale;
b.speed[0] += xCollision;
b.speed[1] += yCollision;
this.speed[0] -= xCollision;
this.speed[1] -= yCollision;
}
}

public void collisionResponse(Ball b) {
double dx = this.position[0] - b.position[0];
double dy = this.position[1] - b.position[1];
double dist = Math.hypot(dx, dy);
double penetration = Math.max(0, radius + b.radius - dist);
float radiusA = (float) (penetration * dx / (dist * 2));
float radiusB = (float) (penetration * dy / (dist * 2));
this.position[0] += radiusA;
this.position[1] += radiusB;
b.position[0] -= radiusA;
b.position[1] -= radiusB;
}[/source]
0

Share this post


Link to post
Share on other sites
There is no easy way to do this without implementing a sequential impulse constraint solver which breaks down the multiple collision case into multiple iterations of pairwise constraints. Check out the code for Box2D or Chipmunk Physics for a simple example.
0

Share this post


Link to post
Share on other sites
One way I would try in this situation is to not check for collision at all when it enters. To me it seems that at the moment it enters, there is only one way to go and it's basically "stuck" in between the 2 walls. Once it enters, perhaps you can let it follow a path of some sort and when it goes out again, check for collisions again. This way you also ensure you don't get unwanted behavior from the collision response.
0

Share this post


Link to post
Share on other sites
[quote name='Rld_' timestamp='1348732106' post='4984262']
One way I would try in this situation is to not check for collision at all when it enters. To me it seems that at the moment it enters, there is only one way to go and it's basically "stuck" in between the 2 walls. Once it enters, perhaps you can let it follow a path of some sort and when it goes out again, check for collisions again. This way you also ensure you don't get unwanted behavior from the collision response.
[/quote]

Do you mean I have to create a pre-determined path once the object gets near? Man, that's a bit challenging to come up with something like that... Especially when creating one...

EDIT: Creating a pre-determined path: Very advanced... It took a lot of energy, but I didn't manage it. Can't find anything that tells me how to start creating a pre-determined path... Bezier curve... Edited by tom_mai78101
0

Share this post


Link to post
Share on other sites
I wonder why your body stil vibrating after it comes out of "gate"?
I had problem something like yours.
Try to make softer collision responce , how to say, do not responce fully:
softness=0..1;
b.position[0] -= radiusA*softness;
b.position[1] -= radiusB*softness;
place more two circles with soft responce on gate circles with full response, but with bigger radius...
but its very dependant on situation in game, good to see real situation in game Edited by serumas
0

Share this post


Link to post
Share on other sites
You mean something like this:

[img]http://i1207.photobucket.com/albums/bb464/tom_mai78101/Untitled-8.png[/img]


EDIT:

Ok, I have created a Beizer Curve. Now, I will be working my way to get the Beizer Curve path correct. Last, the problem may not seem as difficult as I thought it would be. If I just set the starting position of the Beizer Curve as the object's current position, and using boolean conditions to switch to moving on a Beizer Curve, I might be able to move the object through the funnel, and toggle back to letting the user take control and disable the Beizer Curve movement.

The more I see it, the more I believe that this is the solution... Will post in the future.

Picture:

[img]http://i1207.photobucket.com/albums/bb464/tom_mai78101/Untitled-9.png[/img] Edited by tom_mai78101
0

Share this post


Link to post
Share on other sites
Multiple collisions are quite likely, but there is a big difference between checking for collisions and reacting to them, trying to do both at the same time will lead you to this kind of design dilemas.

What I do is check for collisions first, store any positive results, and then give the owner of a collision body a list of references to all the objects it collided with at that frame, then you can address the problem with much more info, you know you collided with two objects and you van adjust the ball trajectory accordingly without causing that ping pong effect.

Its also useful to make a difference between the event of two objects colliding for first time and the detection of collision between two objects we know were colliding last frame.
0

Share this post


Link to post
Share on other sites
Do you know how to adjust the ball trajectory? I would have 2 vectors obtained from two different collision events, but I would also have no clue on making them "merge" into one vector.
0

Share this post


Link to post
Share on other sites

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  
Followers 0