Skip to main content
gamedev.net
🔒 Locked

problem with physics

Started by chitti Jan 17, 2010 at 11:31 PM 6 replies 1.1k views
Original Post
chitti
chitti
Iam very poor in physics.Iam working on a simple game in which I want to move an object shown by the movement of a car in the following link.please help me out. link: http://www.brainycreatures.org/physics/acceleration.asp Thanks in advance.
unbird
unbird
What language do you use ? What graphics API ? What have you done already and what did not work ? Can you show us your source code ?
pulpfist
pulpfist
Here is one way we can make an object move. You will have to find a physics book to get a better understanding of the formulas used. Or you can search for online info like this

@destination - A 2D vector
@position - A 2D vector
@velocity - A 2D vector
@frametime - Scalar value (milliseconds since last render frame)

To move the object:
destination = position + velocity * frametimeposition = destination...


To manipulate speed we could do something simple, like:
if(KeyDown(A))    velocity.x -= speed;if(KeyDown(D))    velocity.x += speed;...


Try this first, and post back if you get any problems
chitti
chitti
Thanks for your reply with valuable information. It seems I have to learn alot before posting questions. Do you have any sites which gives a better idea on "physics in gaming".
chitti
chitti
Original post by pulpfist
Here is one way we can make an object move. You will have to find a physics book to get a better understanding of the formulas used. Or you can search for online info like this


Thanks for your reply with valuable information. It seems I have to learn alot before posting questions. Do you have any sites which gives a better idea on "physics in gaming".
unbird
unbird
There's actually one here at GameDev. It covers even something close to your problem (see 2D car).

After a quick search, I found this probably appropriate for an introduction: Game Physics 101.

[edit]
Quote:

It seems I have to learn alot before posting questions.


Not at all, this IS the Beginners Forum, actually. Your initial "question" was just not specific enough.

[Edited by - unbird on January 20, 2010 6:25:53 AM]
chitti
chitti
Original post by unbird
There's actually one here at GameDev. It covers even something close to your problem (see 2D car).


Actually Im using C++ language and Im trying to move a bat with constant acceleration. with your help I made it. Now I wanted to make collision detection of the moving bat with moving ball. I googled on this topic but its very confusing for me.Any simple example would be appreciated. Here's my code.


if( keypressed )
{
if(Speed < 10.0)
Speed += Acceleration;
Velocity += Speed;
RedPX += Velocity ;
}
else
{
if(Speed > 0 )
{
Speed -= Acceleration;
Velocity += Speed ;
RedPX += Velocity;
}
}

RedPX is the new position of the bat.This works fine for me now how to detect a collision b/w a bat and ball.
unbird
unbird
Glad to hear about your first success.

First when posting source, use tags (explained here, and here). This will make reading easier.

Then: It's always good to post all relevant code. From the code you provided, I can only guess what type the variables are and I have no idea how they are initialized.

Ok. As far as I can tell, you want to achieve sort of a breakout/arkanoid game now, not a car anymore. This is more complex. Anyway, guessing from your code, you still do something in one dimension, not yet something pulpfist suggested. Is that so ? You definitively need 2D-vectors (coordinates).

Before going into collisions, which will need further abstractions (i.e. several objects, not just one alone) post more code.

[edit]
If you really want to do collision in one dimension, you can just compare your two object's positions and check if they are close, for instance

batPosition = position of your bat
ballPosition = position of the ball
if(abs(batPosition - ballPosition) < 10.0){   // collision occured!}



[Edited by - unbird on January 22, 2010 3:12:08 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.