-
Search Results
-
I have my own health script . I wanna use the software to play the death animation clip , because I been having some issues the playing the clip with unity3d animator control . The gameobject has to deactivate and then play the death animation clip first. Here is a look at my health script . I also most forgot to mention . The models are a fbx file .
public bool Invincible { set { m_Invincible = value; } } public float MaxHealth { set { m_MaxHealth = value; } } public float MaxShield { set { m_MaxShield = value; } } public float CurrentHealth { get { return m_CurrentHealth; } } public float CurrentShield { get { return m_CurrentShield; } } public float ShieldRegenerativeAmount { set { m_ShieldRegenerativeAmount = value; } } public AudioClip deathClip; public bool isSinking; static Animator anim; public int dieState; void Start () { anim = GetComponent<Animator> (); }
protected virtual void Awake()
{anim = GetComponent <Animator>();
m_GameObject = gameObject;
m_Transform = transform;
m_Rigidbody = GetComponent<Rigidbody>();SharedManager.Register(this);
m_CurrentHealth = m_MaxHealth;
m_CurrentShield = m_MaxShield;// Register for OnRespawn so the health and sheild can be reset.
EventHandler.RegisterEvent(m_GameObject, “OnRespawn”, OnRespawn);
}private void DieLocal(Vector3 position, Vector3 force)
{
// Notify those interested.
EventHandler.ExecuteEvent(m_GameObject, “OnDeath”);
EventHandler.ExecuteEvent<Vector3, Vector3>(m_GameObject, “OnDeathDetails”, force, position);// Spawn any objects on death, such as an explosion if the object is an explosive barrell.
for (int i = 0; i < m_SpawnedObjectsOnDeath.Length; ++i) {
ObjectPool.Instantiate(m_SpawnedObjectsOnDeath[i], transform.position, transform.rotation);
}// Destroy any objects on death. The objects will be placed back in the object pool if they were created within it otherwise the object will be destroyed.
for (int i = 0; i < m_DestroyedObjectsOnDeath.Length; ++i) {
if (ObjectPool.SpawnedWithPool(m_DestroyedObjectsOnDeath[i])) {
ObjectPool.Destroy(m_DestroyedObjectsOnDeath[i]);} else {
Object.Destroy(m_DestroyedObjectsOnDeath[i]);
}
}// Deactivate the object if requested.
if (m_DeactivateOnDeath) {
Scheduler.Schedule(m_DeactivateOnDeathDelay, Deactivate);
GetComponent<AudioSource>().Play();
anim.SetBool(“isDead”,false);}
}
-
This topic was modified 2 months, 3 weeks ago by
Fail2016.
Hi, I’ve noticed when I reimport from a platform change that the AI forgets the custom extensions (in the extensions tab) it is set to use. Not a huge problem but annoying to reset them…
Thx,
ChrisTopic: FieldSerializer Issue
RAIN version: RAIN 2.1.11.0
I got the following warning sometimes:FieldSerializer: Couldn’t deserialize type: System.Type (ShipMotorController)
My custom motor class below:
using RAIN.Action; using RAIN.Core; using UnityEngine; using RAIN.Serialization; // Need to serialize otherwise the values in editor will be reset [RAINSerializableClass] public class ShipMotorController : RAIN.Motion.BasicMotor { public override void UpdateMotionTransforms() { // Only consider position AI.Kinematic.Position = AI.Body.transform.position; AI.Kinematic.ResetVelocities(); } public override void ApplyMotionTransforms() { // Only consider position AI.Kinematic.UpdateTransformData(AI.DeltaTime); AI.Body.transform.position = AI.Kinematic.Position; } }
Before:
https://www.dropbox.com/s/bmnqj20jep26p9x/ShipMotorController.png?dl=0After:
https://www.dropbox.com/s/47l5ffe8ykpqh64/BasicMotor.png?dl=0When the warning happens, the prefab with RAIN AI Rig script attached and had ShipMotorController selected will be reset to basic motor.
Please advise.
Thanks!
Hello i was writing my own custom motor to get rain Ai working with the arongranberg A* Pathfinding Project ( Free version ), i getting it working but when it callculates a new path i get “lag” on the movement ..
if anyone can help me with this i will be very Grateful with that
so here is the code:
using UnityEngine; using System.Collections; using RAIN.Serialization; using RAIN.Motion; using Pathfinding; [RAINSerializableClass] public class AstarMotor : RAINMotor { [RAINSerializableField] private float _rotationSpeed = 15f; [RAINSerializableField] private float _closeEnoughDistance = 3.5f; [RAINSerializableField] private float _waitpointDistcance = 3.0f; [RAINSerializableField] private float _breakSpeed = 8f; [RAINSerializableField] private float _repathTime = 0.5f; [RAINSerializableField] private bool _debug; private Rigidbody _Body; private Seeker _Seeker; private Path _Path; private int _CurrentwaypointIndex = 0; private Vector3 _LastPosition = Vector3.zero; private float timer; private float rtimer; private bool Canrepath; private Vector3 _destvalue; private Vector3 DestinationPath { get { if (_Path != null) { if (_CurrentwaypointIndex < _Path.vectorPath.Count) { return _Path.vectorPath[_CurrentwaypointIndex]; } else { return Destination; } } else { return AI.Kinematic.Position; } } } private Vector3 Destination { get { Path curr = _Path; if (curr != null && curr.vectorPath.Count > 0 ) { int lastindex = curr.vectorPath.Count - 1; return curr.vectorPath[lastindex]; } else { return AI.Kinematic.Position; } } set { if (_Seeker != null ) { _destvalue = value; Canrepath = true; } } } void OnPathComplete( Path p ) { if(_debug) Debug.Log( AI.Body.GetInstanceID() + ": Yep ! We got a Path, has an Error?: " + p.error); _Path = p; _CurrentwaypointIndex = 0; } private float RemainingDistance { get { return Vector3.Distance(AI.Kinematic.Position, MoveTarget.Position); } } private float _Speed = 0; public override float DefaultSpeed { get { return AI.WorkingMemory.GetItem<float>("Speed"); } set { AI.WorkingMemory.SetItem("Speed", value); } } public override float DefaultCloseEnoughDistance { get { if (MoveTarget.IsValid) { return Mathf.Max(_closeEnoughDistance, MoveTarget.CloseEnoughDistance); } else { return _closeEnoughDistance; } } set { _closeEnoughDistance = value; } } public override float DefaultRotationSpeed { get { return _rotationSpeed; } set { _rotationSpeed = value; } } void MoveCharacter() { // if we are not at our target if (!IsAt(MoveTarget.Position) && _Speed > 0f) { // Movement Vector3 MoveDir = DestinationPath - AI.Kinematic.Position; Vector3 Motion = MoveDir.normalized * _Speed; _Body.velocity = Motion; // Distance Check float wDistance = Vector3.Distance(AI.Kinematic.Position, DestinationPath); if (wDistance <= _waitpointDistcance) { _CurrentwaypointIndex++; } else { // Rotation Vector3 rotateMotion = Motion.normalized; rotateMotion.y = 0; if (rotateMotion != Vector3.zero) { Quaternion tr = Quaternion.LookRotation(rotateMotion); Quaternion lerprotation = Quaternion.Slerp(_Body.transform.rotation, tr, _rotationSpeed * Time.deltaTime); if(_debug) Debug.DrawRay(AI.Kinematic.Position, rotateMotion * 10f, Color.blue); AI.Body.transform.rotation = lerprotation; } } } else { _Body.velocity = Vector3.Lerp(_Body.velocity, Vector3.zero, _breakSpeed * Time.deltaTime); } } public override void BodyInit() { base.BodyInit(); _Body = AI.Body.GetComponent<Rigidbody>(); _Seeker = AI.Body.GetComponent<Seeker>(); if (_Body == null) _Body = AI.Body.AddComponent<Rigidbody>(); if (_Seeker == null) _Seeker = AI.Body.AddComponent<Seeker>(); } // Update public override void UpdateMotionTransforms() { AI.Kinematic.ParentTransform = Matrix4x4.identity; AI.Kinematic.Position = AI.Body.transform.position; AI.Kinematic.ResetVelocities(); if (Canrepath == true) { timer += Time.deltaTime; if (timer >= _repathTime) { float distance = Vector3.Distance(Destination, _destvalue); if (_Seeker != null && _Seeker.IsDone() && distance > _waitpointDistcance ) { // _Path = null; _Seeker.StartPath(AI.Kinematic.Position, _destvalue, OnPathComplete); timer = 0; Canrepath = false; } } } if (MoveTarget.IsValid ) { MoveCharacter(); } rtimer += Time.deltaTime; if (rtimer >= _repathTime) _Speed = 0f; AI.Kinematic.Orientation = AI.Body.transform.rotation.eulerAngles; } public override bool IsAt(Vector3 aPosition) { Vector3 dir = aPosition - AI.Kinematic.Position; dir.y = 0; float d = dir.magnitude; return d <= DefaultCloseEnoughDistance; } public override bool Move() { if (!MoveTarget.IsValid) return false; Vector3 tEndMoved = (_LastPosition - MoveTarget.Position); tEndMoved.y = 0; _Speed = DefaultSpeed; if ( _Path == null || !Mathf.Approximately(tEndMoved.sqrMagnitude, 0) ) { Destination = MoveTarget.Position; _LastPosition = MoveTarget.Position; return IsAt(Destination); } if (_Path.CompleteState != PathCompleteState.Complete || _Path.CompleteState != PathCompleteState.Partial) return false; return RemainingDistance <= DefaultCloseEnoughDistance; } public override void ApplyMotionTransforms() { } public override bool Face() { return true; } public override bool IsAt(MoveLookTarget aTarget) { return IsAt(aTarget.Position); } public override bool IsFacing(Vector3 aPosition) { return true; } public override bool IsFacing(MoveLookTarget aTarget) { return true; } public override void Stop() { } public override bool Allow3DMovement { get { return false; } set { } } public override bool AllowOffGraphMovement { get { return false; } set { } } public override bool Allow3DRotation { get { return false; } set { } } }
Hey guys, I searched around the forum,but I couldn’t find an answer. I have this weird problem. I declare a public array of transforms(or anything) in a custom element, and when I enter it’s size in the Rain inspector and press enter, it resets back zero. So I can’t assign whatever I need to the array. It only gets populated from code. What am I doing wrong?
Thanks!Hi I use a pooling system for my enemies and I’ve noticed that when one is respawned the behavior tree is in the same state as when it was destroyed creating some wonky behavior. Boo wonkiness. Is there an easy way to reset the behavior tree when de/respawned? I’ve tried toggling the ai component off and on, and disabling the AI GO altogether and none of that seems to reset the bx tree.
-
This topic was modified 5 months, 1 week ago by
christougher.
Topic: A serialization bug
Hi all,
I find a series bug of RAIN serialization!As I write some script, whether RAIN code or not, if any script has error, all prefabs have RAIN AI data will be reset!
That is intolerable and maddening on Unity AI developing: I should re-fill all AI data such as BasicMemory again and again!
To say nothing of extending code such as customized sensor.Could it be fixed in a patch or by myself?
Best Regards.
I am currently having trouble with my behavior tree. I have it set up so that my AI patrols a path and attacks(custom action) an object until death. Once it is dead, follow the patrol again, but once the first object is attacked and destroyed, they won’t attack any other ones. I feel like I have to reset the minds target component and then reset the behavior tree and again look for another enemy but I am unsure of how to do this.
-
This topic was modified 2 months, 3 weeks ago by