/
Agent Aim

Agent Aim

from maya import cmds

import AtomsMath
import AtomsCore
import Atoms
import AtomsUtils
from AtomsMaya.utils import agentgroup
from AtomsMaya.hostbridge.atomsgroup import MayaAtomsGroupHostBridge
 


class AgentAimModule(Atoms.BehaviourModule):

    def __init__(self):
        Atoms.BehaviourModule.__init__(self)

        metadata = self.attributes()
        metadata.addEntry("target", AtomsCore.Vector3Metadata())

    def initFrame(self, agents, agroup):
        target = self.attributes().getEntry("target").get()

        for agent in agents:
            agent_position = agent.metadata()["position"].value()
            new_direction = target - agent_position
            new_direction.normalize()
            agent.metadata()["direction"].set(new_direction)


'''
MAYA SETUP 
'''
from maya import cmds

def register():
    Atoms.BehaviourModules.instance().registerBehaviourModule("agentAim",
                                                              AgentAimModule,
                                                              True)


def setup():
    cmds.file(new=True, f=True)
    cmds.tcAtoms(init=True)
    register()
 
    agent_group = agentgroup.create_agent_group()
    ag = MayaAtomsGroupHostBridge()
    ag.set_app_obj(agent_group)
    ag.add_module("gridLayout")
    ag.add_module("stateMachine")
    ag.add_module("agentAim")
    ag.set_display_type(2)
    
    int_type_str = AtomsCore.IntMetadata.staticTypeStr()
    str_type_str = AtomsCore.StringMetadata.staticTypeStr()
    
    cmds.playbackOptions(min=1, max=50)
    
    s = cmds.spaceLocator()[0]
    cmds.setAttr(s + ".t", 200, 50, -120)
    cmds.setKeyframe(s)
    cmds.currentTime(50)
    cmds.setAttr(s + ".t", 420, 50, 200)
    cmds.setKeyframe(s)
    cmds.currentTime(1)

    ag.set_metadata_value("stateMachine", "state", int_type_str, 1)

    cmds.connectAttr(s + ".t", agent_group + ".atoms_agentAim_target")
    
    
setup()

Related content

Reading the world joint matrices of an agent
Reading the world joint matrices of an agent
More like this
Introduction
Read with this
Creating agent groups
Creating agent groups
More like this
State machine debugger data
State machine debugger data
More like this
Behaviour module handling
Behaviour module handling
More like this
Access agent data (AtomsUnreal)
Access agent data (AtomsUnreal)
More like this

Copyright © 2017, Toolchefs LTD.