Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Let's see if I understood correctly. First, you rotate your sprite. After that, you accelerate it forward. In that case:</p> <pre><code>// Called when player hits screen edge private void Bounce() { Rotation = Rotation * -1; Velocity = Velocity * -1; //I THINK THIS IS THE PROBLEM SoundManager.Vulture.Play(); } </code></pre> <p>Let's suposse your sprite has no rotation when it looks up. In that case, if it's looking right it has rotated 90º, and its speed is v = (x, 0), with x > 0. When it goes out of the screen, its rotation becomes -90º and the speed v = (-x, 0). <strong>BUT you're pressing the up key and Accelerate method is called so immediately the speed becomes v = (x, 0) again.</strong> The sprite goes out of the screen again, changes its velocity to v = (-x, 0), etc. That produces the weird bounce. I would try doing this:</p> <pre><code>private void Bounce() { Rotation = Rotation * -1; SoundManager.Vulture.Play(); } </code></pre> <p>and check if it works also up and bottom. I think it will work. If not, use two different Bounce methods, one for top/bottom and another one for left/right. </p> <p>Your second question... It's a bit difficult. In Physics, things reach a max speed because air friction force (or another force) is <strong>speed-dependent.</strong> So if you increase your speed, the force also increases... at the end, that force will balance the other and the speed will be constant. I think the best way to simulate a terminal speed is using this concept. If you want to read more about terminal velocity, take a look on Wikipedia: <a href="http://en.wikipedia.org/wiki/Terminal_velocity" rel="nofollow">http://en.wikipedia.org/wiki/Terminal_velocity</a></p> <pre><code>private void Accelerate() { Acceleration.X = Math.abs(MotorForce - airFriction.X); Acceleration.Y = Math.abs(MotorForce - airFriction.Y); if (Acceleration.X &lt; 0) { Acceleration.X = 0; } if (Acceleration.Y &lt; 0) { Acceleration.Y = 0; } Velocity.X += (float)Math.Cos(Rotation) * Acceleration.X Velocity.Y += (float)Math.Sin(Rotation) * Acceleration.Y airFriction.X = Math.abs(airFrictionConstant * Velocity.X); airFriction.Y = Math.abs(airFrictionConstant * Velocity.Y); } </code></pre> <p>First, we calculate the accelartion using a "MotorForce" and the air friction. The MotorForce is the force we make to move our sprite. The air friction always tries to "eliminate" the movement, so is always postive. We finally take absolute values because the rotation give us the direction of the vector. If the acceleration is lower than 0, that means that the air friction is greater than our MotorForce. It's a friction, so it can't do that: if acceleration &lt; 0, we make it 0 -the air force reached our motor force and the speed becomes constant. After that, the velocity will increase using the acceleration. Finally, we update the air friction value. </p> <p>One thing more: you may update also the value of airFriction in the Deccelarate method, even if you don't consider it in that method.</p> <p>If you have any problem with this, or you don't understand something (sometimes my English is not very good ^^"), say it =)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload