Question: Normalforce (in the universe)?

  • Thread starter Xcrypt
  • Start date
  • Tags
    Universe
In summary, the game developer attempted to create a tank game where the player controls the tank and must avoid collisions with planets. The game developer attempted to calculate the normal force required to stop the tank from falling through the crust of the planet.
  • #1
Xcrypt
21
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: 500
Last edited:
Space news on Phys.org
  • #2
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.
 
  • #3
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?
 
  • #4
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.
 
  • #5
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.
 
  • #6
Thanks, very clarifying :)
 

FAQ: Question: Normalforce (in the universe)?

1. What is normal force in the universe?

Normal force is a type of contact force that objects experience when they are in direct contact with each other. It is perpendicular to the surface of contact and is caused by the repulsion of the atoms in the objects.

2. How is normal force different from other forces?

Normal force is different from other forces because it is a reaction force that only exists when two objects are in direct contact. It is also always perpendicular to the surface of contact, whereas other forces may act at different angles.

3. What is the purpose of normal force in the universe?

The purpose of normal force in the universe is to prevent objects from passing through each other when they are in contact. This is due to the repulsive forces between atoms, which create a barrier that prevents objects from occupying the same space.

4. How is normal force related to gravity?

Normal force and gravity are often discussed together because they are both contact forces that act on objects. However, they have opposite directions - normal force acts perpendicular to the surface of contact, while gravity acts in a downward direction towards the center of the Earth.

5. Can normal force be negative?

No, normal force cannot be negative. It is always directed perpendicular to the surface of contact and therefore has a positive value. If a force is acting in the opposite direction, it would not be considered a normal force, but rather a different type of force such as tension or friction.

Similar threads

Back
Top