News Forums RAIN General Discussion and Troubleshooting Enemy Preb Doesn't Work Properly

Tagged: 

This topic contains 2 replies, has 3 voices, and was last updated by  Kade514 1 month, 3 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #40719

    Cyrawnis
    Participant

    Hello everyone,

    I’m fairly new to rain and was just trying to get a prototype project set up.

    I’m having difficulties setting up a prefab enemy that I can use to duplicate as multiple enemies patrolling the same scene.

    Basically, my hierarchy is a CapsuleHolder containing:
    1 - the capsule character
    2 - the rain AI component.

    The capsule character then has an animator component attached to it.
    The rain AI component with two sensors for sight and touch.

    I also have a basic waypoint route that has two points. When I press play the capsule will correctly play the animation for walking and navigate around the obstacles in my navmesh to ping pong between the two points. It also correctly detects the entity I have set to my player to chases after me accordingly - attacking once i’m within the touch radius. All animations play correctly for each state. So my behavior tree is working as expected 100%.

    Now, my issue is that when I create a prefab using this CapsuleHolder and use the prefab to create another CapsuleHolder (1) enemy within the scene the new enemy just sits in place without navigating the navmesh and plays the idle animation. Also, it seems that on the CapsuleHolder (1)’s AI component the sensors it uses are placed around the original CapsuleHolder. Even when I change the sensors mount points to correctly be on the CapsuleHolder (1) this does not solve my issue.

    How can I properly set this up so that I can use a preb to spawn in multiple enemies?

    Any help is appreciated, and I can provide more context if necessary.

    Thanks!

    Edit:

    Additionally, I created a minimalistic version of this of just a enemyHolder with a cube and an AI inside of it. The AI is set to a behavior tree that is simply parallel>waypointpatrol>move that navigates back and forth between the two waypoints. Even when I duplicate this the second enemyHolder does not patrol. Thoughts?

    • This topic was modified 2 months ago by  Cyrawnis.
    • This topic was modified 2 months ago by  Cyrawnis.
    #40823

    christougher
    Participant

    Check the Ai prefab as to whether or not the variables and or the body are set correctly.

    #40832

    Kade514
    Participant

    For whatever reason, Rain seems to no longer properly save the transforms of aspects, sensors, etc, and that messes up the AI. My workaround was to make a bit of code which is called on Start and which sets the mounts and aspects. You’ll need to have the sensors and aspects already in the AI, but if you fill out the resulting array it should solve your issue.

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using RAIN.Core;
    using RAIN.Entities;
    public AIMounting mounts;
    private AIRig m_ThisAIRig;
    private EntityRig m_ThisEntityRig;
    [System.Serializable]
        public class Sense
        {
            public string senseName;
            public Transform location;
        }
        [System.Serializable]
        public class Aspect
        {
            public string aspectName;
            public Transform location;
        }
        [System.Serializable]
        public class AIMounting
        {
            public GameObject body;
            public GameObject entity;
            public Sense[] senses;
            public Aspect[] aspects;
        }
    // Use this for initialization
        public virtual void Start ()
        {
            m_ThisAIRig = gameObject.GetComponentInChildren<AIRig>();
            m_ThisEntityRig = gameObject.GetComponentInChildren<EntityRig>();
            MountAIComponents();
        }
        private void MountAIComponents()
        {
            m_ThisAIRig.AI.Body = mounts.body;
            //mounts the sensors at the specified location
            foreach (Sense aiSense in mounts.senses)
            {
                m_ThisAIRig.AI.Senses.GetSensor(aiSense.senseName).MountPoint = aiSense.location;
            }
            m_ThisEntityRig.Entity.Form = this.gameObject;//mounts.entity;
            //sets aspect mount locations.
            foreach (Aspect aiAspect in mounts.aspects)
            {
                m_ThisEntityRig.Entity.GetAspect(aiAspect.aspectName).MountPoint = aiAspect.location;
                m_ThisEntityRig.Entity.GetAspect(aiAspect.aspectName).PositionOffset = new Vector3(0,1,0);
            }
        }
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.