Jump to content

  • Log In with Google      Sign In   
  • Create Account


prushik

Member Since 17 Apr 2010
Offline Last Active Mar 05 2013 10:25 PM
-----

Topics I've Started

Collision response forces in rigid body simulation

04 February 2013 - 09:22 PM

Basically, its the same project I'm working on, 2D driving game. I have 2 (or more, but 2 for now) vehicles using rigid body based physics, all in 2D. right now there are no other obsticles to collide with, just the 2 vehicles.

I think I can detect collisions perfectly (based on bounding boxes only), and those same collision detection functions return the point of contact relative to both vehicles. I can easily determine the velocity of those points on each vehicle.

So, what I did was take the difference of those 2 speeds, and multiply that by the other vehicle's mass to get the force, and then apply that to the vehicle at the point of contact, do that for both vehicles. The result looks ok for stuff like head on collisions, or high speed collisions, if one vehicle is stationary, etc... probably not too realistic, but doesn't need to be perfect, just not too absurd.

However, the real problem occurs when I try to push another vehicle with the players vehicle, the result isn't bad for the first few frames, but then the player starts to push its way into the NPC vehicle, so the images overlap.

So, what is the problem here? I'm a bit confused about how this is happening, at this point, the vehicles are even the same mass, so if I mix up which vehicle's mass I am multiplying, the result should be the same.

This seems like something that should have a well known solution, I'm just too dumb to figure it out on my own.


creating random rectangles to cover a grid

10 December 2012 - 09:08 PM

This should be simple, but for some reasons I am having trouble coming up with a solution.
Essentially I have a structure which contains 2 2D vectors (coordinate and size). I have about 20 instances of this structure. I also have a grid. What I want to do is randomly set the coordinates and sizes of these 20 structures so that they all fit into the grid and do not overlap each other.

The problem is that I need to have all of them in there. If I just start tossing them in randomly, its possible for one to become too big and take up the entire grid, which prevents others from forming, causing an infinite loop right in the beginning of my program (which sucks). I also want to minimize the possibility of very very small rectangles, since that could make it too easy for the player of my game (winning could consist of eliminating a specific rectangle).

Any ideas?

Tractor Trailers with Rigid Bodies in 2D (hinge constraints)

02 December 2012 - 07:06 PM

Basically what I want to do is implement some basic tractor trailer physics using rigid bodies. Right now I have rigid body physics that look decent (good enough for me right now) for a single segment vehicle (car, bus, etc...), however, tractor trailers are important in my game. I've been thinking about this problem for some time and searching the internet, and have come up with so much information, but nothing that really solves the problem. It seems it should be easy, this is just a simple 2d game.
Should I create a point on both rigid bodies that acts similar to a wheel and applies force to the rigid body equivalent to what is needed to keep the bodies connected? or is there some other way that this should be done?
Both segments will need to exert forces on each other.

I found a guy who wrote an algorithm here: http://gamedev.stack...-physics-system

It seems to be what I was looking for, but from the page it seems there may be some problems with it. And the author seems unsure of himself. So, is that the right approach to take?

(I'm using C and SDL2, if you want to know)

EDIT: Also note that my simulation should be simpler than the article I linked to, since I only have one hinge point where it looks like the article actually has 2.

Drawing images along a line

13 November 2012 - 09:02 PM

I wasn't sure whether this should go in the Math/Physics area, or here (Graphics).
I am working on a game at the moment, a 2D driving game in C using SDL2 (just pretend I'm using SDL if you aren't familiar with SDL2). At the beginning of the game, it generates a world by creating and connecting nodes in a way that resembles (kind of) roads and intersections. For testing, I am drawing a line between connected nodes, however, nobody wants to drive around on thin black lines, we want to drive on roads. So, I created an image or a road segment.
What I want to do it draw that image along the lines connecting the nodes. There are many lines, so I want to only draw images on the segments which intersect the view. I've been pondering this issue for some time, and I just can't think of an efficient solution, only brute force solutions, which would involve lots of math happening each step, which will be certain to slow things down. So far I haven't actually tried to implement anything yet since the few ideas I have suck.
Any ideas?


Question summary:
if I have a line from node[0].coord to node[1].coord how can I determine the correct places to draw a series of images on top of the line such that the entire line is covered and images touch each other at the ends? (image is only about 64x64, but line will be at least 500 pixels long)

Linking nodes in a grid

31 October 2012 - 04:01 AM

Hey guys, hows it going?
Essentially, what I am trying to do is generate a grid. (done)
Populate the grid randomly with some number of nodes. (done)
Iterate through all the nodes, generate a random number between 1 and 4 and link to that many nearby nodes. (ehh..)
Dissolve the grid leaving only the array of connected nodes behind.

So, creating and populating the grid are no problem. Linking the nodes is the issue I am struggling with. Yes, I know it should be easy to do, however, I discovered that my code becomes way too complicated really quickly. There must be some kind of existing algorithm for this kind of thing, right?
For the grid, I just made a 2D array called grid (I am using C), the nodes are also an array. I just randomly place a node in the grid, generating a new random if that grid space is already occupied.
After that, I iterate through the nodes, this is where the trouble starts. I want to find the closest node in the array (that isn't already linked to the current node) to the current node, and then create a link by adding the node's index to an array in the node structure, and the links should go both ways (doubly linked).
I also want to favor nodes in opposite directions of existing links if there are any, and also favor nodes which can be connected with horizontal or vertical lines (avoid diagonal lines somewhat) - These rules are not 100% necessary.

Is there some existing algorithm for this? how would you accomplish this task? thanks for the help, I love you

PARTNERS