Question: Normalforce (in the universe)?

  • Thread starter Thread starter Xcrypt
  • Start date Start date
  • Tags Tags
    Universe
AI Thread Summary
The discussion revolves around implementing normal force in a 2D space shooter game where a tank interacts with planets. The user seeks to understand how to calculate the normal force to prevent the tank from falling through a planet's surface upon collision. Key insights include treating the normal force as a constraint on motion, determining if the tank's trajectory intersects with the planet, and calculating the impulse based on momentum changes during collisions. The conversation emphasizes that the normal force should counteract all other forces acting on the tank while in contact with the planet. Understanding these principles will help in accurately simulating the tank's behavior in the game.
Xcrypt
Messages
20
Reaction score
0
Hello, I am studying game development, I'm in my first year and have to make a 2D game in C++ for a project. I'm sorry if this is considered homework and thus posted it in the wrong board. Also my knowledge of physics is very basic so please excuse me for my amateurism. I tried to contact my teachers about this problem but they don't seem to understand it.

The game is a 2D shooter game in space, where you have control over a tank as player. In one level, there are different planets. The projectiles the tank shoot follow paths based on the addition of multiple 'planet-object' attraction force vectors. The tank itself also has to be attracted to the planets. I will show you some code of how I did this:

it is based on the formula: F=G*((m1*m2)/r^2)

Vector2D PlanetList::CalculateGravityVector(Point2D ObjectPosition, double ObjectMass, InputState* inputStatePtr)
{
//Calculate vector: the addition of all attraction force vectors of the object to a specific planet

double F,distance,angle;
Point2D PlanetPosition;
Vector2D vdistance, tempGravityVector;
Vector2D GravityVector(0,0);
Vector2D AngleZero(1,0);

for (int x=0 ; x<MAXNRPLANETS ; ++x)
{
if (m_PlanetPtrArr[x]!=0)
{
//First: Calculate the attraction force between the object and the [x]'nd planet in the list
//F = G * ((m1*m2)/r^2)
PlanetPosition = m_PlanetPtrArr[x]->GetPosition();
vdistance = PlanetPosition-ObjectPosition;
distance = vdistance.Length();
F = m_GravitationConstant*((ObjectMass*m_PlanetPtrArr[x]->GetMass())/(distance*distance));

//Put the Force in a Vector2D
//To achieve that, calculate the angle first

angle = vdistance.AngleWith(AngleZero);
tempGravityVector.x = cos(angle)*F;
tempGravityVector.y = sin(angle)*F;

//Add this vector to the Vector2D we need.
GravityVector+=tempGravityVector;
}
}


return GravityVector;
}

This function will be implemented in a Tick() function, this means that in the program, the vector will be calculated for every tick (usually 1/60 s).

I think I have this part right. But I also want to implement a force (I think it is called normalforce), that makes it so when the tank and the planet collide, that makes the tank unable to fall through the crust of the planet.

My question is: what kind of force is this, and how do I calculate this?

(I made a quick sketch of the problem in paint, check attachments.)

At first I thought this was Fn = -Fz, but then I realized this wouldn't work, because suppose the tank is moving at 200pixels/second, with an acceleration of only 2px/s^2, and a mass of 500 units, only the acceleration and the mass play a role, meaning that the velocity of the tank would not increase anymore, but still stay at 200px/s when the tank collides with the crust of a planet.

Help is much appreciated.
 

Attachments

  • Gravity Problem.jpg
    Gravity Problem.jpg
    20.9 KB · Views: 527
Last edited:
Space news on Phys.org
The normal force is whatever force is required so that the planet doesn't move. The best way to implement it is simply as a constraint on the motion. I.e. figure out if the line from the tank's old position to the tank's new position intersects the surface of the planet, if so then the tanks new position is the intersection and the tank's new velocity is the planet's velocity.
 
That is indeed a good solution. However I am still kind of curious how to calculate this force, I may be an amateur in physics, I actually am quite interested in them. Any ideas?
 
This is a collision, so the average force on an object in a collision depends on two things: the change in the object's momentum (Δp) and the duration of the collision (Δt).

F=Δp/Δt

In your case if the planet is at rest then Δp is equal and opposite to p and Δt is your video game's time step.
 
The problem here is that there will first be a collision and force of collision and then the tank will presumably ride along with the planet or at least maintain motion only along the surface.

Since you are using ticks instead of continuous time what you really are working with is impulses (force time tick length) which has units of momentum. The force of impact will vary over the time the impact takes place but you can figure the total impulse is that which is sufficient to stop the tank's motion relative to the planet m(Vplanet - Vtank) or if you want to have it coast along the planetary surface, the impulse will be just the normal component.

You can also allow it to bounce elastically by reversing the normal momentum.

This impact impulse would occur at the first tick where the tank and planet intersect. You would then, while they are in contact, maintain the normal force equal and opposite to the normal component of all other forces acting on the tank.

If you're standing on the ground you may have many forces acting upon you, Earth's gravity, the pull of the moon, some guy giving you a knoogie etc. The ground doesn't just oppose gravity but the net force trying to push you into it.

Ultimately it is acting as a very stiff spring, pushing back on you in proportion to the small amount you sink into it. That amount will be determined by other forces acting on you and by your inertia if you're being slammed into the ground. If you try to model it this way though you will end up with bouncing objects. There is a dissipation of energy occurring as well. You leave an indention in the Earth as you move away so it doesn't push back returning the energy required to depress it. (and given enough force it leaves you deformed as well.) To model that non-bouncing repulsion simply eliminate the normal velocity as suggested, or implement the one-time impact force or impulse I suggested.
 
Thanks, very clarifying :)
 
https://en.wikipedia.org/wiki/Recombination_(cosmology) Was a matter density right after the decoupling low enough to consider the vacuum as the actual vacuum, and not the medium through which the light propagates with the speed lower than ##({\epsilon_0\mu_0})^{-1/2}##? I'm asking this in context of the calculation of the observable universe radius, where the time integral of the inverse of the scale factor is multiplied by the constant speed of light ##c##.
The formal paper is here. The Rutgers University news has published a story about an image being closely examined at their New Brunswick campus. Here is an excerpt: Computer modeling of the gravitational lens by Keeton and Eid showed that the four visible foreground galaxies causing the gravitational bending couldn’t explain the details of the five-image pattern. Only with the addition of a large, invisible mass, in this case, a dark matter halo, could the model match the observations...
Hi, I’m pretty new to cosmology and I’m trying to get my head around the Big Bang and the potential infinite extent of the universe as a whole. There’s lots of misleading info out there but this forum and a few others have helped me and I just wanted to check I have the right idea. The Big Bang was the creation of space and time. At this instant t=0 space was infinite in size but the scale factor was zero. I’m picturing it (hopefully correctly) like an excel spreadsheet with infinite...

Similar threads

Back
Top