I am a beginner in games development and using c++ and opengl to work around with vector class developed by me to move an object.
i have successfully managed to move my object on the positive x direction but i want my object to go in the reverse direction after reaching a defined value. in my project that value is 1.0. here is a piece of my code that will help understand my problem better.
void moveUp()
{
part.velocity.x += 0.01;
part.velocity.y += 0.03;
part.position.x += part.velocity.x;
part.position.y += part.velocity.y;
part.acceleration.x -= 0.0;
part.acceleration.y -= 0.01;
part.velocity.x += part.acceleration.x;
part.velocity.y += part.acceleration.y;
cout << endl <<"this is the position on the x coordinate: " << part.position.x << endl;
if(part.position.y <= 0.15)
{
part.acceleration.x = 0;
part.acceleration.y = 0;
part.velocity.x = 0;
part.velocity.y = 0;
}
cout << endl << "this is the velocity on the x coordinate: " << part.velocity.x << endl;
if(part.position.x > 1)
{
part.velocity.x = 0;
part.velocity.y = 0;
part.velocity.x -= 0.01;
part.velocity.y += 0.03;
part.position.x += part.velocity.x;
part.position.y += part.velocity.y;
part.acceleration.x += 0;
part.acceleration.y -= 0.01;
part.velocity.x += part.acceleration.x;
part.velocity.y += part.acceleration.y;
}
}
after running this code the object keeps bouncing at one place on y coordinate and does not move back on the x coordinate. when i print out the velocity of the object on x coordinate..it gives me the encircled value in the attached picture.
[attachment=23960:screenshot.jpg]
any help is appreciated. Also i want the object to jump once and come to a stationary position instead of using a glutTImerFunc(), that keeps calling the update function again and again after i press a key to make the object jump, the object keeps bouncing.