Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It sounds like you need to calculate heading vectors for the ship based on the its current orientation in radians. For example:</p> <pre><code>double xVector = Math.Sin(orientationInRadians); double yVector = Math.Cos(orientationInRadians); </code></pre> <p>Then use the left and right arrows to control the ship's current orientation. Once you have the vector you can calculate the location of the ship that is 10 units away from its current position along the heading vector. First you need to scale the vector to a unit (length of 1) vector.</p> <pre><code>double magnitude = sqrt(xVector*xVector + yVector*yVector); double unitVectorX = xVector/magnitude; double unitVectorY = yVector/magnitude; </code></pre> <p>Now you have a vector that is 1 unit long but still points in the ship's current orientation. Next move the ship with positionX and positionY as current its coordinates.</p> <pre><code>double distanceToTravel = 10; double newPositionX = positionX + unitVectorX*distanceToTravel; double newPositionY = positionY + unitVectorY*distanceToTravel; </code></pre> <p>You'll want to track the ship's position and orientation with doubles or floats even if you end up rendering with a system that only allows ints. You shouldn't store the current position and orientation using the rendering engine's precision or you will start to see strange jumps and pauses as you move and rotate. Also, using the above you can make distanceToTravel non-constant (imagine accelerating while the key is pressed instead of moving a fixed distance from a key press).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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