Original Post
🔒 Locked
problem with physics
Advertisement
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:
To manipulate speed we could do something simple, like:
Try this first, and post back if you get any problems
@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
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".
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]
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]
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]
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.
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
[Edited by - unbird on January 22, 2010 3:12:08 AM]
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.
Advertisement