# Applying Force in the most basic way....

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

## Recommended Posts

So I have a pool table ball, and instead of giving it an initial velocity I give it an initial force

 void TakeShot(PoolGame& game) { game.poolBalls[CUE].forceX = 1000.0f * sin(Math::ToRadians(game.playerAngle)); game.poolBalls[CUE].forceY = 1000.0f * cos(Math::ToRadians(game.playerAngle)); } 

where game.playerAngle gives the direction of the shot, so I am creating a force in X and y components, and the game.poolBalls[CUE] is a struct referencing my cue ball on a pool table

Then, using Euler integration (Yeah, I know, I just want to get the basics working first)

 Euler(balls[ball].position[X],balls[ball].currentVelocity[X],balls[ball].forceX - frictionCoefficient,1.0f,dt); Euler(balls[ball].position[Y],balls[ball].currentVelocity[Y],balls[ball].forceY - frictionCoefficient,1.0f,dt); 

 void Euler(float& position,float& velocity,float force,float mass,float dt) { if(force < 1.0f) force = 0.0f; position += velocity * dt; velocity += (force/mass) * dt; } 

However my balls bounce against the cushions like balls on the floor....

 void CheckForCollisionsAgainstWalls(Ball* balls) { for(int ball = 0; ball < TOTALBALLS; ball++) { if(balls[ball].position[X] - BALL_RADIUS < MIN_X) { balls[ball].position[X] = MIN_X + BALL_RADIUS; balls[ball].currentVelocity[X] = -balls[ball].currentVelocity[X]; } if(balls[ball].position[X] + BALL_RADIUS > MIN_X + TABLE_LENGTH) { balls[ball].position[X] = MIN_X + TABLE_LENGTH - BALL_DIAMETER; balls[ball].currentVelocity[X] = -balls[ball].currentVelocity[X]; } if(balls[ball].position[Y] - BALL_RADIUS < MIN_Y) { balls[ball].position[Y] = MIN_Y + BALL_RADIUS; balls[ball].currentVelocity[Y] = -balls[ball].currentVelocity[Y]; } if(balls[ball].position[Y] + BALL_RADIUS > MIN_Y + TABLE_WIDTH) { balls[ball].position[Y] = MIN_Y + TABLE_WIDTH - BALL_DIAMETER; balls[ball].currentVelocity[Y] = -balls[ball].currentVelocity[Y]; } } } 

Am I going about all of this the wrong way?

See video below!

P.S Sorry about the music, didn't realise it was being recorded!

##### Share on other sites
The force should only be applied when you accelerate ("take shot") the ball. Instead, you apply a constant force to the ball, just like gravity. That's why it looks like as if the ball was bouncing on the floor.

So after the initial acceleration of the ball (take shot), set the force to zero.

Maybe you have just begun with the physics implementation, but I don't see why it is good that you use the force from taking a shot, but you don't use any forces in any other part of the simulation. Make the whole thing force based, or make it otherwise, but mixing the two will make things very messy soon. Edited by szecs

##### Share on other sites
Using a force to simulate impacts between two hard objects is not numerically stable. You'd have to use an extremely small timestep so that the 'hard' collision becomes 'soft'. You could make it work by isolating a single impact and integrating only this impact in detail with a very small timestep. In practice it is much easier to use the impulse or conservation of momentum.

##### Share on other sites
 float Front_force = Throttle_to_force( Throttle ); //thrust force val ThrustForce_vec = YPRangle.rf; //thrust force direction (normlaized vector) ThrustForce_vec = vector_multiple(ThrustForce_vec, Front_force); result_force = ThrustForce_vec; Acceleration = result_force; //divide vector by float Acceleration = Acceleration / mass; // a = F / m dk = ( dt*dt ) / 2.0f; //(a * t^2 )/ 2 //s = V0*t + (a * t^2 )/ 2 accvel = Normalize( Acceleration ); Translation = Acceleration; Translation = vector_multiple(Translation, dk); s = V*dt; accvel = vector_multiple(accvel, s); Translation = vectors_add(Translation, accvel); pos = vectors_add(pos, Translation ); 

Explenation:

apply forces

calc acceleration
calc time

use foruma s = v0*t + [a(t*t) / 2]

i don't see friction applied in your app

consider that i use: meters as distance, seconds as time, newtons as force, kilograms as mass Edited by ___

##### Share on other sites
you sbstarct frici0on value minus vector

fiction is a normalized vector multipied by its length = friction typek

1. 1
Rutin
36
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633346
• Total Posts
3011445
• ### Who's Online (See full list)

There are no registered users currently online

×