dim3 Forum

Full Version: node problem HELP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I don't usually use nodes, but I need them for cover for enemies and for enemies to jump out behind you when you can't see them.
Is there anything wrong with this:
Code:
const FY_TROOPER_ATTACK_NODE=1;
or this:
Code:
obj.motionVector.walkToNode('cover','attack',FY_TROOPER_ATTACK_NODE);
???

Also, do I need to assign a number to FY_TROOPER_ATTACK_NODE to use it? I can't figure out why the numbers are assigned to the Joe Foe node walker ones :|.

There are multiple cover nodes and multiple attack nodes, but they they are connected so the bot should go to the nearest one with that name, right?
ccccc Wrote:I don't usually use nodes, but I need them for cover for enemies and for enemies to jump out behind you when you can't see them.
Is there anything wrong with this:
Code:
const FY_TROOPER_ATTACK_NODE=1;
or this:
Code:
obj.motionVector.walkToNode('cover','attack',FY_TROOPER_ATTACK_NODE);
???

Also, do I need to assign a number to FY_TROOPER_ATTACK_NODE to use it? I can't figure out why the numbers are assigned to the Joe Foe node walker ones :|.

There are multiple cover nodes and multiple attack nodes, but they they are connected so the bot should go to the nearest one with that name, right?

Yes, node walking is always shortest path. The numbers are just there so that when a walk is ending and you get an event, you can have some sort of ID to tell what was happening. The numbers don't mean anything to the core, just something you can possible use when the walk ends.

[>] Brian
Wait, I AM using the event word thing (FY_TROOPER_ATTACK_NODE), but does it need a number/what does the number do?

Why is the character just running in place (I DID rebuild paths)? It IS getting to that part in the code :|.
In my experience, when you have two nodes named the same thing, the engine only pays attention to the first node created. For example:
You add a node and name it 'A'.
You add a node and name it 'A'.
You add a node and name it 'B'.
You connect them all and Rebuild Paths.
You tell your character to walkToNode( 'A', 'B', 1);
Your character will go to the 'A' node created first (even if he's sitting right on top of the second 'A' node), then meander over to the 'B' node.

In other words, you'll need to name each of your nodes differently if you want everything to behave properly.

To answer your questions about FY_TROOPER_ATTACK_NODE, that is an ID that you can use if you want to track your character's movement. For example, this is a simple script that moves JoeFoe in a triangle from node A to node B to node C to node A etc...
Code:
const WALK_TO_A = 1;
const WALK_TO_B = 2;
const WALK_TO_C = 3;

function joeFoeConstruct(obj)
{
    obj.model.on=true;
    obj.model.name='JoeFoe';
    obj.model.lit=DIM3_MODEL_LIT_VERTEX;
    
    obj.forwardSpeed.walk=35;
    obj.forwardSpeed.acceleration=1.0;
}

function joeFoeFinishNodeWalk( obj, id )
{
    switch( id )
    {
        case WALK_TO_A:
            obj.motionVector.walkToNode( 'A', 'B', WALK_TO_B );
            return;
        case WALK_TO_B:
            obj.motionVector.walkToNode( 'B', 'C', WALK_TO_C );
            return;
        case WALK_TO_C:
            obj.motionVector.walkToNode( 'C', 'A', WALK_TO_A );
            return;
    }
}

function event( obj ,mainEvent, subEvent, id, tick)
{
    switch( mainEvent )
    {
        case DIM3_EVENT_CONSTRUCT:
            joeFoeConstruct( obj );
            return;
    
        case DIM3_EVENT_SPAWN:
            obj.motionVector.walkToNode('A','B', WALK_TO_B);
            return;
            
        case DIM3_EVENT_PATH:
            joeFoeFinishNodeWalk( obj, id );
            return;
    }
}

You can see that I used the constants WALK_TO_A, WALK_TO_B, and WALK_TO_C to tell where JoeFoe was in his journey. I could have just as easily used integers instead of constants, like so:

Code:
function joeFoeFinishNodeWalk( obj, id )
{
    switch( id )
    {
        case 1:
            obj.motionVector.walkToNode( 'A', 'B', 2 );
            return;
        case 2:
            obj.motionVector.walkToNode( 'B', 'C', 3 );
            return;
        case 3:
            obj.motionVector.walkToNode( 'C', 'A', 1);
            return;
    }
}

But this method makes things harder to read and understand. Constants are there to be your friends and make it so you don't have to remember the event ID's of everything going on in your scripts. Smile
beavertoes Wrote:In my experience, when you have two nodes named the same thing, the engine only pays attention to the first node created.

Yes -- you'll want to keep them unique. Nice post, beavertoes!

[>] Brian
Code:
// ***********************************************************
// BOT: FY Trooper
// TEAM: UNSEEN
// © copyright 2007 Tray-More-Street Games
// ***********************************************************
var mood='idle';
var victim;
var wait=10;
var style='normal';

const FY_TROOPER_ATTACK_NODE=1;

function fyTrooperConstruct(obj)
{
    obj.model.on=true;
    obj.model.name='FY Trooper';
    obj.model.lit=DIM3_MODEL_LIT_VERTEX;
    obj.model.shadow.on=true;

    obj.sight.sideFieldAngle=0;
    obj.sight.lookFieldAngle=90;
    obj.sight.sideFieldDivision=1;
    obj.sight.lookFieldDivision=8;
    obj.sight.distance=90000;

    obj.setting.team=DIM3_TEAM_RED;
    obj.setting.openDoors=false;
    obj.setting.damage=true;
    obj.setting.ignorePickUpItems=true;

    obj.health.maximum=50;
    obj.health.start=50;

    obj.turnSpeed.facingWalk=5;
    obj.turnSpeed.motionWalk=5;
    obj.turnSpeed.facingRun=5.2;
    obj.turnSpeed.motionRun=5.2;
    obj.turnSpeed.facingCrawl=4;
    obj.turnSpeed.motionCrawl=4;
    obj.turnSpeed.facingAir=4;
    obj.turnSpeed.motionAir=4;

    obj.size.x=1299;
    obj.size.z=1318;
    obj.size.y=4476;
    obj.size.weight=100;
    
        // setup weapon
        
    obj.weapon.add('BL15_bot');
}

function fyTrooperSpawn(obj)
{
    obj.model.animation.showMesh('BL15');
    if (obj.setting.getParameter(0)=='hide') {
        style='hide';
        mood='hide';
        obj.watch.start(9000);
    } else {
        obj.watch.start(90000);
    }
    obj.model.animation.start('idle guard');
}

function fyTrooperWatch(obj,subEvent)
{
    if (obj.watch.objectTeam==DIM3_TEAM_BLUE) {
        if (subEvent==DIM3_EVENT_WATCH_OBJECT_NEAR) {
            if (style=='normal') {
                obj.model.animation.startThenChange('idle guard to agg','idle agg')
                victim=obj.watch.objectId;
                mood='attack';
                obj.motionVector.turnToObject(victim);
                fyTrooperFire(obj);
                obj.watch.stop();
            } else {
                obj.motionVector.walkToNode('A','B',FY_TROOPER_ATTACK_NODE);
                obj.model.animation.start('run agg');
            }
        }
    }
}

function fyTrooperFire(obj)
{
    if (mood=='attack') {
        if (obj.sight.testObject(victim)) {
            obj.model.animation.startThenChange('fire idle','idle agg');
            obj.weapon.fire('BL15_bot',1);
            wait=5;
        }
        obj.event.chain(wait,'fyTrooperFire');
    }
}

function fyTrooperDie(obj)
{
    obj.setting.contact=false;
    obj.watch.stop();
    obj.motionVector.stop();
    mood='dead';
    obj.model.animation.startThenChange('trip agg','dead');
    obj.event.clearChain();
    obj.watch.stop();
}

function fyTrooperEndPath(obj,subEvent,id)
{
    if (subEvent==dim3_EVENT_PATH_DONE) {
        if (id==FY_TROOPER_ATTACK_NODE) {
        mood=attack;
        obj.model.animation.start('idle agg')
        fyTrooperFire(obj);
        }    
    }
}

function event(obj,mainEvent,subEvent,id,tick)
{
    switch (mainEvent) {
    
        case DIM3_EVENT_CONSTRUCT:
            fyTrooperConstruct(obj);
            return;
    
        case DIM3_EVENT_SPAWN:
            fyTrooperSpawn(obj);
            return;

        case DIM3_EVENT_PATH:
            fyTrooperEndPath(obj,subEvent,id);
            return;

        case DIM3_EVENT_WATCH:
            fyTrooperWatch(obj,subEvent);
            return;

        case DIM3_EVENT_DIE:
            fyTrooperDie(obj);
            return;
    }
}
Thats my script, still doesn't work. (changed the nodes to A and B to make sure there were no spelling errors).

Start from spawn function then go through the code as if style=hide Wink.
Try giving him a little bit of obj.forwardSpeed.walk and just a touch of obj.forwardSpeed.acceleration. Wink Poor fella can only run in circles.
:D
LOL THANK YOU!!!!!!!!!11111oneoneone
I hate it when I do that :P.
Reference URL's