0
\$\begingroup\$

I have a 2D top-down jetboat that is moving (has a x, y velocity). I apply the velocity by multiplying against the delta time dt:

position.x += velocity.x * dt
position.y += velocity.y * dt

Before that however I calculate the velocity with:

velocity.x += acceleration * cos(angle) * dt
velocity.y += acceleration * sin(angle) * dt


angle = (heading_current * M_PI) / 180;

Angle is in radians, and it should be changing the velocity x, y based on the angle at which the force is being applied.

Two things seem to be going on, one is that the angle is at 0° and the boat travels toward 90°, and two, when I change the angle to anything else, the boat just continues on it 90° path. What am I doing wrong?

I hope that makes sense.

\$\endgroup\$
10
  • \$\begingroup\$ "But it's not" — what symptoms are you observing instead? \$\endgroup\$
    – DMGregory
    Mar 15 at 10:12
  • \$\begingroup\$ Have updated my question with what is not working \$\endgroup\$
    – fresh
    Mar 15 at 10:24
  • 1
    \$\begingroup\$ What heading do you call 0° here? +y or -y? Do you notice any deflection at all when changing the angle, even if it's not as sharp a turn as you expected? \$\endgroup\$
    – DMGregory
    Mar 15 at 11:09
  • \$\begingroup\$ Hmm, there is a gradual change, we are talking minutes to see anything. 0deg should be north right? But my boat is going 90deg, east \$\endgroup\$
    – fresh
    Mar 15 at 11:20
  • \$\begingroup\$ No, using the mathematical convention of x = cos(angle) as you're using, zero degrees points toward x+ (usually East in typical graphing layouts). If you want 0 to point up, swap cos and sin. You may have to negate one or the other depending on your coordinate, system, whether y+ points up or down, and whether you want angles to increase clockwise or counterclockwise. \$\endgroup\$
    – DMGregory
    Mar 15 at 11:24

0

You must log in to answer this question.

Browse other questions tagged .