Why is fire being delayed in robocode

156 Views Asked by At
package com.gshs;

import robocode.*;

public class Gshs_21043 extends Robot
{
    public void run() {
        
        while(true) {
            
            turnRadarRight(90);
            
        }
    }

    public void onScannedRobot(ScannedRobotEvent e) {
        turnRight(e.getBearing());
        fire(3);
        ahead(e.getDistance());
    }

    public void onHitByBullet(HitByBulletEvent e) {
        // Replace the next line with any behavior you would like
        back(10);
    }

    public void onHitWall(HitWallEvent e) {
        // Replace the next line with any behavior you would like
        back(20);
        
    }   
}

In onScannedRobot, I wrote fire(3) then ahead, but when I build and run, when my robot scans the target robot, it runs towards the target, and when it arrives there, my robot shoots.

It acts just like the two lines are switched, so I tried switching two lines just in case, but this didn't work. Can anyone tell me what is wrong?

1

There are 1 best solutions below

0
On BEST ANSWER

I think I found why

In while(true) I wrote turnRadarRight(90);

Maybe this is the priority action so it would delay the shooting

So I changed it to turnRadarRight(30); it will take less time to finish the act

It worked!