Hairie

Members
  • Content count

    11
  • Joined

  • Last visited

Community Reputation

109 Neutral

About Hairie

  • Rank
    Member
  1. How do I reset my game?

    I use "bulk" C# code. I get the elapsed time by calling QueryPerformancetimer regularly...the only wrapper i have is tao for opengl.
  2. Hello, I am making a 2d ping pong game in c#. If the ball hits the net, the balls position and velocity should be reset to the initial values at the start of the game. I know that the global timer therefore needs to be reset, but I don't know how to do it correctly. All my attempts yet to reset the game have failed. Here is the call of the ball's update method by testing class update's method: [source lang="C#"] public void Update(double elapsedTime) { ball.Update(elapsedTime,yPosition,xPosition,tablesurface,netsurface,ref c, ref r1, ref r2); }[/source] Here is the code of the ball update method: [source lang="C#"] enum ballStatus{Reset,Play}; ballStatus status = ballStatus.Play; public void Update(double time, double height, double newXPos, List<Point> collisionsrfc,List<Point> netcollisionsrfc, ref Circle c,ref Rectangle rect1,ref Rectangle rect2) { if(start_timer) { timer+=time; } if((timer > 10.0) && (start_timer)) { status = ballStatus.Reset; } else { status = ballStatus.Play; } if(status == ballStatus.Play) { Xstart = newXPos; Ystart = height; Tilted_Throw(time,Ystart,Xstart,collisionsrfc,netcollisionsrfc,ref c, ref rect1, ref rect2); TotalTimePassed+=12*time; SetPosition(GetX,GetY); } if(status == ballStatus.Reset) { SetPosition(-340,70); Xstart=-340; Ystart=70; TotalTimePassed=0; resetvelocity=true; timer=0; start_timer=false; } } [/source] The variable[b] timer[/b] is not the global game timer, but the timer for reseting the game after 10 seconds, if the ball collided with the net. The global timer is the variable [b]TotalTimePassed[/b]. The values [b]-340 [/b]for[b] x[/b] and [b]70[/b] for [b]y[/b] are the initial position values of the ball at the start of the game. If [b]resetvelocity[/b] is true, than the velocity is changed to the desired initial velocity of the ball in the ball's [b]Tilted_Throw[/b] method: [source lang="C#"] if(resetvelocity==false) { _velocity.Y = (velocity_start.Y - g.gravitation * TotalTimePassed); _velocity.X = velocity_start.X; } else { SetStartVelocity(90+rand.Next(0,15),10+rand.Next(5,15)); _velocity.X = velocity_start.X; _velocity.Y = velocity_start.Y; resetvelocity=false; } [/source] With [b]SetStartVelocity [/b]I set the new starting velocity([b]velocity_start[/b])(a bit different than the initial velocity, because ive added randomness). The problem is, whenever the ball hits the net, [b]timer [/b]will first go to [b]0 [/b]and then go up to [b]10[/b], then again to [b]0[/b] and then again up to [b]10 [/b]etc. After every 10 seconds the ball will repeat its motion near the net and at this point i notice, that the ball is only displayed for 1 frame at the [b]desired position(-340,70)[/b]. Please help me or give me solutions for this problem. Thanks in advance!
  3. Hello, I am currently making a pixel based 2D table tennis game where I need to to find the exact point the ball hits the table. For simplicity reasons I have't programmed the spin of the ball yet. Can anyone help me with formulas or something else helpful? Thanks!
  4. yes your right, even if the resulting acceleration is > 0, the velocity will still be negative and only shortly after velocity will become positive and the object will rise again
  5. Okay, but, if buyancy is bigger than its gravityforce it should actually start rising with the resulting accelreation and not decelrate by (g-resulting acceleration)? Because if so, it would decelerate even if it had its maximuim bouyancy force. For example if a body had the density 0.75 and a volume 0f 1000, its gravityforce would be 7357.5N. Its maximum buoyancy would be 9819. The resulting force would be 2452.5 N and the resulting max acceleration would be 3.27 m/s², so it should rise by that acceleration and not sink by(g-resulting acceleration), right?
  6. Yea it makes sense, but you said that if the bouyancy is bigger than its gravityforce only then it will begin to deaccelerate, but what is, if bouyancy is smaller than its gravityforce? Then it should also deaccelerate or not?
  7. Okas, I get that...but how is it, if the bouyancy still is less then the gravity force on the object? How does that affect the resulting acceleration? Because it already slows down, before its buoyancy is bigger than its gravity force ...or not?
  8. Thanks again, I completely forgot to subtract the positive accelerations from g xD, so I would need to apply the new value for g int both the formulas: [b]pK * V_max * g[/b] for the bodyforce and:[b] p_fl * V_immersed *g [/b]for the buoyancy...isn't it? By the way, the object already slows down when it first enters the water isnt it? So g already then must decrease isn' it ? Or am i being wrong?
  9. My first ideas were to calculate the difference between gravity force and bouyancy and to get the resulting acceleration by dividing hte resulting force by the mass of the object. Then i could use the formular y = 0.5 * a * t² for each timestep, resulting in y+=0.5*a*t². Depending on if the resulting force is below or over 0, the object would move either up or down. Each timestep i could recalculate the immersed volume, which would be something like [CODE] v_inWater = s.GetWidth() * s.GetHeight() * (watervolume-y); [/CODE] where watervolume is current immersed volume and y is the amount added/subtracted each timestep, depending on if it is sinking or rising, after that i could recalculate the bouyancy force, then the resulting force and finally the acceleration....is this a right approach or are there some mistakes in it?
  10. Okay, thanks for all these useful responses.... now i have the following situation: An object(a quad in this case) should fall vertically from a specific position into the water with a density lower than that of water...how would I calculate its correct motion within the water, till it stands still? What formulas would i need to calculate its upward and downward motion?