Note that there are some explanatory texts on larger screens.

plurals
  1. POupdate coordinates based on angle and speed
    primarykey
    data
    text
    <p>I see plenty of answers to this riddle on here, but every time I try and implement the answers, they don't seem to work. I wanted to reply to some of the answers, but couldn't. Perhaps it's because of my 'reputation' level? </p> <p>Anyway, it's a simple coordinates problem for a game. Simple for most, but not for me. (suck at math.. hardcore)</p> <p>I've got a spaceship in the middle of the screen. It does not move apart from rotation (user.fAngle). It does have velocity (user.dVelocity) that is used purely for calculating its location in the world. </p> <p>Right now I have the ship moving at a velocity of 1. Which means wherever it 'goes', it's moving at that velocity (again, purely for map coordinate purposes). Doesn't slow down or speed up just yet.. but will eventually. So velocity will eventually be a changing variable.</p> <p>Here is what I have now..</p> <pre><code> double radians = (Math.PI / 180) * ( user.fAngle); worldX = (int)(worldX + user.dVelocity * Math.cos(radians)); worldY = (int)(worldY + user.dVelocity * Math.sin(radians)); </code></pre> <p>user.fangle of course = 0-359</p> <p>worldX and worldY start at 0 when you begin the game. I am trying to modify worldX and worldY each frame based on the ship's angle and hardcoded velocity. </p> <p>For the most part, this works. But what's odd is that at certain times, the coordinates will freeze. Or they'll stop at 0 and not go into the negatives. Again, this only happens at certain times and at certain angles. </p> <p>The other issue I'm seeing is that when the numbers do change, they are always changing at consistent speeds. In other words, let's say north is 0. If I'm moving at an angle of 5, the worldY variable should be changing a lot, but worldX should be changing a little. This is not happening.</p> <p>In my debugging, I've made sure that user.fAngle is indeed within the range of 0-359. I'm not sure what else to check.</p> <p>Thanks for reading, and I appreciate the help.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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