Virtual bullet doesn't line up with real bullets

Jump to navigation Jump to search
Revision as of 4 October 2011 at 01:58.
The highlighted comment was created in this revision.

Virtual bullet doesn't line up with real bullets

I have a virtual gun that fires a virtual bullet, for some reason it's just slightly off when i actually fire.

MisalignedVirtualBullet.png

What's the proper way to align and fire? I think my timing is just off.

    Ultimatebuster22:56, 3 October 2011

    I would guess this is the result of the Robocode idiosyncrasy where a bullet is fired before the gun is turned (so if you do setTurnGunRightDegrees(10), setFire(3), execute(), the bullet is fired before the gun is turned right 10 degrees). So your actual aim is probably the aim from the previous turn, while your predicted is from the current turn.

      Skotty23:28, 3 October 2011
       

      Well... can't really tell without more information what's wrong, but my first guess about what's wrong, is that perhaps you're not accounting for how within a tick, firing happens before gun turning does. The angle you fire at when you call setFire() is the angle resulting from the prior tick's setTurnGun() type call.

        Rednaxela23:28, 3 October 2011
         

        Yeah that's correct, the setFire is from the last tick.

        What's a typical pattern for robocode as to code placement? I'm currently placing the gun turning code in the while true loop and the firing code in onScannedRobot

        and it's wrapped with if (getGunHeat() == 0.0)

        Should I change that layout? (also add && getGunTurnRemaining() == 0.0 to the fire wrap?)

          Ultimatebuster02:03, 4 October 2011
           

          Using onScannedRobot or run is totally just a matter of preference - for 1v1 it won't make any difference, really. It could also be an off-by-1 error in the bullet source location - it should be your location on the tick you called setFire. Or your target angle was farther than your gun could move during that tick, in which case the getGunTurnRemaining == 0 check would solve it.

            Voidious02:18, 4 October 2011
             

            I know if i combined the 2 logics in 1 function, the code would fail (for me at least)

            (Also Voidious: I'm testing my bot against yours now because it has pretty debugging graphics and I can see my weaknesses :P Also I perform better against your bot if i don't fire :P)

              Ultimatebuster02:58, 4 October 2011