[Pogamut-list] Raycasting problem

jakub.gemrot pogamut-forum at diana.ms.mff.cuni.cz
Thu Nov 8 07:30:39 CET 2012


Re: Raycasting problem

Author: jakub.gemrot

Hi!

Unfortunately its working flawlessly for me. So I expect there would be some configuration problem between your version of UT2004 and GB2004 and mine.

1) do you have UT2004 patched? (part of the official pogamut installer)
2) do you have latest version of GB2004? (I know I've asked, but it worth a shot try to reinstall JUST UT2004Patch + GameBots2004 from the latest Pogamut 3.3.1 installer)
3) did you alter GameBots2004.ini in any way?

Just to be sure, I'm copy pasting a code I'm running here + copy pasting my GameBots2004.ini

===================
CODE
===================

package cz.cuni.amis.pogamut.ut2004.examples.raycastingbot;

import javax.vecmath.Vector3d;

import cz.cuni.amis.introspection.java.JProp;
import cz.cuni.amis.pogamut.base.utils.guice.AgentScoped;
import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotModuleController;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Configuration;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.RemoveRay;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.AutoTraceRay;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage;
import cz.cuni.amis.pogamut.ut2004.utils.UT2004BotRunner;
import cz.cuni.amis.pogamut.ut2004.utils.UnrealUtils;
import cz.cuni.amis.utils.exception.PogamutException;
import cz.cuni.amis.utils.flag.FlagListener;

/**
 * Example of Simple Pogamut bot, that randomly walks around the map. Bot is
 * incapable of handling movers so far. 
 * 
 *  
 * The crucial method to read
 * through is {@link RaycastingBot#botInitialized(GameInfo, ConfigChange, InitedMessage)},
 * it will show you how to set up ray-casting.
 * 
 * 
 * We recommend you to try this bot on DM-TrainingDay or DM-Albatross or DM-Flux2.
 * 
 *
 * @author Ondrej Burkert
 * @author Rudolf Kadlec aka ik
 * @author Jakub Gemrot aka Jimmy
 */
@AgentScoped
public class RaycastingBot extends UT2004BotModuleController {

    // Constants for rays' ids. It is allways better to store such values
    // in constants instead of using directly strings on multiple places of your
    // source code
    protected static final String FRONT = "frontRay";
    protected static final String LEFT45 = "left45Ray";
    protected static final String LEFT90 = "left90Ray";
    protected static final String RIGHT45 = "right45Ray";
    protected static final String RIGHT90 = "right90Ray";
    
    private AutoTraceRay left, front, right;
    
    /**
     * Flag indicating that the bot has been just executed.
     */
    private boolean first = true;
    private boolean raysInitialized = false;
    /**
     * Whether the left45 sensor signalizes the collision. (Computed in the
     * doLogic())  Using {@link RaycastingBot#LEFT45} as the key for the
     * ray.
     */
    @JProp
    private boolean sensorLeft45 = false;
    /**
     * Whether the right45 sensor signalizes the collision. (Computed in the
     * doLogic())  Using {@link RaycastingBot#RIGHT45} as the key for the
     * ray.
     */
    @JProp
    private boolean sensorRight45 = false;
    /**
     * Whether the front sensor signalizes the collision. (Computed in the
     * doLogic())  Using {@link RaycastingBot#FRONT} as the key for the
     * ray.
     */
    @JProp
    private boolean sensorFront = false;
    /**
     * Whether the bot is moving. (Computed in the doLogic())
     */
    @JProp
    private boolean moving = false;
    /**
     * Whether any of the sensor signalize the collision. (Computed in the
     * doLogic())
     */
    @JProp
    private boolean sensor = false;
    /**
     * How much time should we wait for the rotation to finish (milliseconds).
     */
    @JProp
    private int turnSleep = 250;
    /**
     * How fast should we move? Interval .
     */
    private float moveSpeed = 0.6f;
    /**
     * Small rotation (degrees).
     */
    @JProp
    private int smallTurn = 30;
    /**
     * Big rotation (degrees).
     */
    @JProp
    private int bigTurn = 90;

    /**
     * The bot is initialized in the environment - a physical representation of
     * the bot is present in the game.
     *
     * @param config information about configuration
     * @param init information about configuration
     */
    @Override
    public void botInitialized(GameInfo info, ConfigChange currentConfig, InitedMessage init) {
        // initialize rays for raycasting
        final int rayLength = (int) (UnrealUtils.CHARACTER_COLLISION_RADIUS * 10);
        // settings for the rays
        boolean fastTrace = true;        // perform only fast trace == we just need true/false information
        boolean floorCorrection = false; // provide floor-angle correction for the ray (when the bot is running on the skewed floor, the ray gets rotated to match the skew)
        boolean traceActor = false;      // whether the ray should collid with other actors == bots/players as well

        // 1. remove all previous rays, each bot starts by default with three
        // rays, for educational purposes we will set them manually
        getAct().act(new RemoveRay("All"));

        // 2. create new rays
        raycasting.createRay(LEFT45,  new Vector3d(1, -1, 0), rayLength, fastTrace, floorCorrection, traceActor);
        raycasting.createRay(FRONT,   new Vector3d(1, 0, 0), rayLength, fastTrace, floorCorrection, traceActor);
        raycasting.createRay(RIGHT45, new Vector3d(1, 1, 0), rayLength, fastTrace, floorCorrection, traceActor);
        // note that we will use only three of then, so feel free to experiment with LEFT90 and RIGHT90 for yourself
        raycasting.createRay(LEFT90,  new Vector3d(0, -1, 0), rayLength, fastTrace, floorCorrection, traceActor);
        raycasting.createRay(RIGHT90, new Vector3d(0, 1, 0), rayLength, fastTrace, floorCorrection, traceActor);


        // register listener called when all rays are set up in the UT engine
        raycasting.getAllRaysInitialized().addListener(new FlagListener() {

            public void flagChanged(Boolean changedValue) {
                // once all rays were initialized store the AutoTraceRay objects
                // that will come in response in local variables, it is just
                // for convenience
                left = raycasting.getRay(LEFT45);
                front = raycasting.getRay(FRONT);
                right = raycasting.getRay(RIGHT45);
            }
        });
        // have you noticed the FlagListener interface? The Pogamut is often using {@link Flag} objects that
        // wraps some iteresting values that user might respond to, i.e., whenever the flag value is changed,
        // all its listeners are informed

        // 3. declare that we are not going to setup any other rays, so the 'raycasting' object may know what "all" is        
        raycasting.endRayInitSequence();

        // change bot's default speed
        config.setSpeedMultiplier(moveSpeed);

        // IMPORTANT:
        // The most important thing is this line that ENABLES AUTO TRACE functionality,
        // without ".setAutoTrace(true)" the AddRay command would be useless as the bot won't get
        // trace-lines feature activated
        getAct().act(new Configuration().setDrawTraceLines(true).setAutoTrace(true));

        // FINAL NOTE: the ray initialization must be done inside botInitialized method or later on inside
        //             botSpawned method or anytime during doLogic method
    }

    /**
     * Main method that controls the bot.
     *
     * @throws cz.cuni.amis.pogamut.base.exceptions.PogamutException
     */
    @Override
    public void logic() throws PogamutException {
        // mark that another logic iteration has began
        log.info("--- Logic iteration ---");

        // if the rays are not initialized yet, do nothing and wait for their initialization 
        if (!raycasting.getAllRaysInitialized().getFlag()) {
            return;
        }

        // once the rays are up and running, move according to them

        sensorFront = front.isResult();
        sensorLeft45 = left.isResult();
        sensorRight45 = right.isResult();

        // is any of the sensor signalig?
        sensor = sensorFront || sensorLeft45 || sensorRight45;

        if (!sensor) {
            // no sensor are signalizes - just proceed with forward movement
            goForward();
            return;
        }

        // some sensor/s is/are signaling

        // if we're moving
        if (moving) {
            // stop it, we have to turn probably
            move.stopMovement();
            moving = false;
        }

        // according to the signals, take action...
        // 8 cases that might happen follows
        if (sensorFront) {
            if (sensorLeft45) {
                if (sensorRight45) {
                    // LEFT45, RIGHT45, FRONT are signaling
                    move.turnHorizontal(bigTurn);
                } else {
                    // LEFT45, FRONT45 are signaling
                    move.turnHorizontal(smallTurn);
                }
            } else {
                if (sensorRight45) {
                    // RIGHT45, FRONT are signaling
                    move.turnHorizontal(-smallTurn);
                } else {
                    // FRONT is signaling
                    move.turnHorizontal(smallTurn);
                }
            }
        } else {
            if (sensorLeft45) {
                if (sensorRight45) {
                    // LEFT45, RIGHT45 are signaling
                    goForward();
                } else {
                    // LEFT45 is signaling
                    move.turnHorizontal(smallTurn);
                }
            } else {
                if (sensorRight45) {
                    // RIGHT45 is signaling
                    move.turnHorizontal(-smallTurn);
                } else {
                    // no sensor is signaling
                    goForward();
                }
            }
        }

        // HOMEWORK FOR YOU GUYS:
        // Try to utilize LEFT90 and RIGHT90 sensors and implement wall-following behavior!
    }

    /**
     * Simple method that starts continuous movement forward + marking the
     * situation (i.e., setting {@link RaycastingBot#moving} to true, which
     * might be utilized later by the logic).
     */
    protected void goForward() {
        move.moveContinuos();
        moving = true;
    }

    public static void main(String args[]) throws PogamutException {
        // wrapped logic for bots executions, suitable to run single bot in single JVM
        new UT2004BotRunner(RaycastingBot.class, "RaycastingBot").setMain(true).startAgent();
    }
}

===================
GameBots2004.ini
===================
[Engine.GameInfo]
AccessControlClass=Engine.AccessControl
AutoAim=1.000000
GameDifficulty=5.000000
GameSpeed=1.000000
GameStatsClass=IpDrv.MasterServerGameStats
GoalScore=0
GoreLevel=2
HUDType=Engine.Hud
MaplistHandlerType=
MaxIdleTime=0.000000
MaxLives=0
NumMusicFiles=13
SecurityClass=UnrealGame.UnrealSecurity
ServerSkillLevel=
TimeLimit=0
VotingHandlerType=xVoting.xVotingHandler
bAdminCanPause=False
bAllowBehindView=False
bAttractAlwaysFirstPerson=False
bChangeLevels=True
bEnableStatLogging=false
bLowGore=False
bNoBots=False
bStartUpLocked=False
bWeaponShouldViewShake=True
bLargeGameVOIP=False
MaxSpectators=2
MaxPlayers=16

[GameBots2004.BotConnection]
bAllowCheats=True
bAllowPause=true
bDebug=False
bExportGameInfo=true
bExportITC=true
bExportInventory=true
bExportMovers=true
bExportMutators=true
bExportNavPoints=true
bExportPlayers=true
bIgnoreMaxPlayers=False
bIterative=False
bSynchronousMessagesOff=False
visionTime=0.250000
bSynchronousNavPoints=True

[GameBots2004.BotCTFGame]
FriendlyFireScale=0.000000
GoalScore=100
HUDType=XInterface.HudBCaptureTheFlag
LateEntryLives=1
LoginMenuClass=GUI2K4.UT2K4PlayerLoginMenu
MaxLives=0
MaxTeamSize=16
NetWait=5
ResetTimeDelay=0
SpawnProtectionTime=2.000000
TimeLimit=20
bAdjustSkill=False
bAllowControlServer=True
bAllowNonTeamChat=False
bAllowPrivateChat=True
bAllowTaunts=True
bAllowTrans=True
bAllowWeaponThrowing=True
bForceRespawn=False
bPlayersMustBeReady=False
bTeamScoreRound=False
bWeaponStay=true

[GameBots2004.BotDeathMatch]
BotServerPort=3000
ControlServerPort=3001
GoalScore=10
HUDType=XInterface.HudBDeathMatch
LateEntryLives=1
LoginMenuClass=GUI2K4.UT2K4PlayerLoginMenu
MaxLives=0
NetWait=5
ObservingServerPort=49918
ResetTimeDelay=0
SpawnProtectionTime=2.000000
TimeLimit=10
bAdjustSkill=False
bAllowControlServer=True
bAllowPrivateChat=True
bAllowTaunts=True
bAllowTrans=False
bAllowWeaponThrowing=True
bForceRespawn=False
bPlayersMustBeReady=False
bRandomPorts=False
bTeamScoreRound=False
bVehiclesEnabled=True
bWeaponStay=False
RemoteBotController=GameBots2004.ObservedRemoteBot
BotServerClass=GameBots2004.BotServer
HudMutatorClass=GameBots2004.GBHudMutator
ControlServerClass=GameBots2004.ControlServer
bAllowObservingServer=True
ObservingServerClass=GameBots2004.ObservingServer
PortsLog=GBports1348668841755a0

[GameBots2004.BotDoubleDomination]
FriendlyFireScale=0.000000
GoalScore=3
HUDType=XInterface.HudBDoubleDomination
LateEntryLives=1
LoginMenuClass=GUI2K4.UT2K4PlayerLoginMenu
MaxLives=0
MaxTeamSize=16
NetWait=5
ResetTimeDelay=0
SpawnProtectionTime=2.000000
TimeDisabled=10
TimeLimit=20
TimeToScore=10
bAdjustSkill=False
bAllowControlServer=True
bAllowNonTeamChat=False
bAllowPrivateChat=True
bAllowTaunts=True
bAllowTrans=False
bAllowWeaponThrowing=True
bForceRespawn=False
bPlayersMustBeReady=False
bTeamScoreRound=False
bWeaponStay=true

[GameBots2004.BotScenario]
DisperserLocation=(X=682,Y=-1824,Z=-4148)
DisperserRadius=200
FactoryAdrenalineCount=50
FactoryLocation=(X=4399,Y=832,Z=-4525)
FactoryRadius=200
FactorySpawnClass=XPickups.UDamagePack
StrongEnemyName=EmoHawk

[GameBots2004.BotTeamGame]
FriendlyFireScale=0.000000
GoalScore=60
HUDType=XInterface.HudBTeamDeathMatch
LateEntryLives=1
LoginMenuClass=GUI2K4.UT2K4PlayerLoginMenu
MaxLives=0
MaxTeamSize=16
NetWait=5
ResetTimeDelay=0
SpawnProtectionTime=2.000000
TimeLimit=20
bAdjustSkill=False
bAllowControlServer=True
bAllowNonTeamChat=False
bAllowPrivateChat=True
bAllowTaunts=True
bAllowTrans=False
bAllowWeaponThrowing=True
bBalanceTeams=False
bForceRespawn=False
bPlayersMustBeReady=False
bTeamScoreRound=False
bWeaponStay=true

[GameBots2004.ControlConnection]
UpdateTime=0.3000
bAllowPause=True
bExportGameInfo=true
bExportITC=true
bExportInventory=true
bExportKeyEvents=true
bExportMovers=true
bExportMutators=true
bExportNavPoints=true
bExportPlayers=true
bNewProtocol=True

[GameBots2004.ControlServer]
MaxConnections=10

[GameBots2004.GBHUD]
DisplayPlayerPositions=1
NavPointBeaconDrawDistance=500
bDisplayDebug=False
bDisplayHealthBar=True
bDisplayHelp=False
bDisplayInformation=false
bDisplayMyLocation=True
bDisplayNavCubes=False
bDisplayPlayerList=False
bDisplayRoute=false
bDisplayTextBubble=False
bDrawNavPointsGrid=False
bDrawNavPointsNames=True

[GameBots2004.GBScenarioMutator]
AdrenalineAmount=10
AdrenalineRespawnTime=60
DefaultAmmoAmount=1
DefaultRespawnTime=20
FlakInitAmmo=1
FlakMaxAmmo=5
StrongCanPickup=false
StrongDamageScaling=2
StrongEnemyName=emohawk
StrongMaxHealth=40
StrongSpeedMultiplier=0.8
StrongStartHealth=40
WeakCanPickup=true
WeakDamageScaling=1
WeakMaxHealth=150
WeakSpeedMultiplier=1
WeakStartHealth=100

[GameBots2004.RemoteBot]
DefaultRotationRate=(Pitch=3072,Yaw=60000,Roll=2048)
MaxSpeed=2.000000
bAutoSpawn=True
bAutoTrace=False
bDrawTraceLines=False
bIncludeFadeOutInMsg=false
bPerfectLocationAim=false
bShowFocalPoint=False

[UnrealGame.DeathMatch]
MinNetPlayers=1
NamePrefixes[0]=Mr_
NamePrefixes[1]=
NamePrefixes[2]=The_Real_
NamePrefixes[3]=Evil_
NamePrefixes[4]=
NamePrefixes[5]=Owns_
NamePrefixes[6]=
NamePrefixes[7]=Evil_
NamePrefixes[8]=
NamePrefixes[9]=
NameSuffixes[0]=
NameSuffixes[1]=_is_lame
NameSuffixes[2]=
NameSuffixes[3]=
NameSuffixes[4]=_sucks
NameSuffixes[5]=
NameSuffixes[6]=_OwnsYou
NameSuffixes[7]=
NameSuffixes[8]=_jr
NameSuffixes[9]='s_clone
RestartWait=30
bAllowPlayerLights=False
bAutoNumBots=True
bColoredDMSkins=False
bForceDefaultCharacter=False
bPlayersMustBeReady=False
bTournament=False
bWaitForNetPlayers=True

[UnrealGame.UnrealMPGameInfo]
BotMode=5
BotRatio=1.000000
EndTimeDelay=4.000000
MinPlayers=22

=====================

Does this help?

Jimmy

-- 
Reply Link: <http://diana.ms.mff.cuni.cz/main/tiki-view_forum_thread.php?forumId=6&comments_reply_threadId=6&comments_parentId=1067&post_reply=1#form>




More information about the Pogamut-list mailing list