Re: DT in BGT
The goal there was not to have a variable DT. The goal was to use time correctly in the equations, then move according to DT. According to the physics person that is helping me, this example:
VF.x = (V0.x+A.x)*DT*cosine(phi);
is incorrect. He said that you don't use DT as the time, you use actual time, but then move by DT. So, to determine force when the ball his hit, I think my NewShot method would need something like this:
void NewShot(double phi, double theta, bool opponentShot = false)
{
//Making sure that the shot cannot occur when rules do not apply.
if(B.pos.z == 0 or LastShooter == 1 and !opponentShot)
return;
//You can't hit the ball if you're too far away.
if(distance() > 4)
{
env.play_stationary("sounds/miss.ogg", false);
return;
}
//Get current real time.
CT = RealTime.elapsed;
//Account for some rules.
rules.shots++;
if(rules.serving)
{
rules.service++;
MustServe=false;
B.tossing=false;
LastShooter= server;
}
else
{
LastShooter++;
if(LastShooter > 2)
LastShooter = 1;
}
if(LastShooter == 1)
{
//Original values sent to opponent, will have to be changed based on new code.
string message = (deg+180) + ".";
Server.send_reliable(0, message, Ball);
}
rules.bounces = 0;
env.play_2d("sounds/shot.ogg", user.x, user.y, x, y, false);
B.rising=true;
B.moving=true;
if(rules.shots==2)
{
rules.serving = false;
rules.faults = 0;
}
//Set initial vel here, at the moment for debugging and testing purposes, will be changed later.
V0.x = 200;
V0.y = 200;
//Make sure chosen angle is correct. Remember that he has switched it so that phi measures azimuthal angle, and theta measures elevation for some reason in this case.
A.x = SetAngle(phi);
A.y = SetAngle(phi);
Theta(B.pos.z, r);
//Now calculate time that it took to actually complete, to use in the equations, and log the value of T for debugging and testing purposes. NOTE: T is usually 22 or 23.
T = RealTime.elapsed-CT;
test.add_entry("T is " + T + ".");
//Set velocity using T instead of DT.
SetVel();
//This is done because the only way to get the ball sound to play correctly seems to be to have it play every x number of frames. If you know of a better way, let me know.
C.frame = 0;
//Call move method for the ball.
B.move();
}
}
Now, in ball::move, I say:
void move()
{
//Move the ball based on velocity with DT. I had it set velocity each time to account for the change in gravity acceleration.
pos += SetVel()*DT;
//Account for gravity.
A += G;
//For when the ball bounces.
if(pos.z <= 0)
{
moving = false;
bounce();
}
//This is done for the sound. If I don't do it this way, the sound plays so fast that it's just a buzzing that overwhelms everything, and is why I set frames to 0 in the shot method. Again, if you've got a better way, by all means let me know.
if(C.frame == 50)
{
B.slot = env.play_2d("sounds/ball.ogg", user.x, user.y, B.pos.x, B.pos.y, false);
C.frame = 0;
}
env.update_sound_2d(B.slot, B.pos.x, B.pos.y);
}
I hope that made sense. If you've got any better ideas of ways to handle things, please feel free to let me know.
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector