Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411490 Posts in 69371 Topics- by 58428 Members - Latest Member: shelton786

April 25, 2024, 02:44:36 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Pendulum Physics
Pages: [1]
Print
Author Topic: Pendulum Physics  (Read 773 times)
Marchal_Mig12
Level 0
**


View Profile
« on: October 21, 2014, 04:41:42 PM »

Hi everyone,

I was wondering if a pendulum physics can be reproduced by using the same physics I would use for a ball sliding down a line.

E.g.:

given the normal vector dx,dy of a line :

Code:
var D = horSpeed*dx + verSpeed*dy;
var e = 0; // e=1 will bounce fully, e=0 will slide
horSpeed -= dx*D*(1 + e);
verSpeed -= dy*D*(1 + e);

That should be handling collision with a line. However if the ball would be attached by a rope. Can I say that whenever the ball is farther away than the rope's length I could use that piece of code simulate a line collision with the normal vector as illustrated below :



Thanks for you help,

Miguel
Logged
BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #1 on: October 22, 2014, 10:48:41 AM »

Your ideas are right from a physical point of view - the tension force of the string is exactly like a normal force of resting on a slope. In a frictionless world, a ball in a half pipe will move exactly like a ball on a pendulum.

The problem comes when you actually code it. Unlike real life, you'll be evaluating the change in speed only once per game tick, not continuously. This causes small errors that can accumulate unless carefully managed. This is called integration error, and it is a problem almost all physics engines deal with.

Pendulums are well understood, so if you want to animate one there are generally easier ways to do so. It's easier just to record the current angle of the swing, and compute the current swing speed based on the height and conservation of energy - this method will never cause the pendulums position or speed to drift from the correct values (though it is still not perfectly accurate, in some more subtle ways).
Logged
Marchal_Mig12
Level 0
**


View Profile
« Reply #2 on: October 22, 2014, 02:32:17 PM »

Thanks for your reply Boris.

I understand better the integration error problem now. I am not sure if the impact will be important enough for the gameplay to take a hit, but I'll give it a try.

Thanks.

Mig
Logged
Blambo
Guest
« Reply #3 on: October 22, 2014, 02:42:29 PM »

there are a lot of methods out there that can reduce integration errors, for example implicitly defining velocity (velocity = current position - last position, position = velocity*dt + .5*accleration*(dt^2)).

Verlet integration uses this (http://en.wikipedia.org/wiki/Verlet_integration#Discretization_error) to reduce error. but even with this eventually i think you're going to get weird problems when the simulations get complex
Logged
Marchal_Mig12
Level 0
**


View Profile
« Reply #4 on: October 22, 2014, 04:29:21 PM »

where dt is delta time right?
Logged
Blambo
Guest
« Reply #5 on: October 22, 2014, 07:18:15 PM »

yeah. its used to compensate for lag so that things are updated according to seconds, not frames
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic