Пример #1
0
    public static CreateEvent Create(string name, GameObject gameObject)
    {
        TransformEvent t = TransformEvent.Create(gameObject);
        CreateEvent    e = new CreateEvent();

        e.Type     = QuarkEventType.Create;
        e.Id       = t.Id;
        e.Tag      = t.Tag;
        e.Position = t.Position;
        e.Rotation = t.Rotation;
        e.Scale    = t.Scale;
        e.Name     = name;
        return(e);
    }
Пример #2
0
    public override void Reset(BaseAgent agent)
    {
        PlayAreaDistance = AcademyParameters.Update(academy, PlayAreaDistanceKeyVal, PlayAreaDistance);


        /* float spawn = PlayAreaDistance * 0.5f; */
        /* float x = Random.Range(-halfdist, halfdist); */
        /* x += halfdist * Mathf.Sign(x); */
        /* float y = Random.Range(-halfdist, halfdist); */
        /* y += halfdist * Mathf.Sign(y); */

        Quaternion rotation      = Quaternion.Euler(0, Random.Range(0, 360), 0);
        Vector3    polarPosition = rotation * new Vector3(0, 0, Random.Range(PlayAreaDistance * CenterDistance, PlayAreaDistance));

        agent.transform.position = new Vector3(polarPosition.x, PositionY, polarPosition.z);
        agent.transform.rotation = Quaternion.identity;
        agent.transform.Rotate(0, Random.Range(0, 360), 0);

        if (agent.area.EventSystem != null)
        {
            agent.area.EventSystem.RaiseEvent(ResetEvent.Create(agent.gameObject));
            agent.area.EventSystem.RaiseEvent(TransformEvent.Create(agent.gameObject));
        }
    }
Пример #3
0
    public override void RunAction(BaseAgent agent, float[] act)
    {
        GameObject gameObject = agent.gameObject;
        Transform  transform  = gameObject.transform;
        Rigidbody  rigidbody  = gameObject.GetComponent <Rigidbody>();

        if (rigidbody == null)
        {
            return;
        }

        Vector3 dirToGo   = Vector3.zero;
        Vector3 rotateDir = Vector3.zero;

        var forwardAxis = (int)act[forwardIdx];
        var rightAxis   = (int)act[rightIdx];
        var rotateAxis  = (int)act[turnIdx];

        switch (forwardAxis)
        {
        case 1:
            dirToGo = transform.forward;
            break;

        case 2:
            dirToGo = -transform.forward;
            break;
        }

        switch (rightAxis)
        {
        case 1:
            dirToGo = transform.right;
            break;

        case 2:
            dirToGo = -transform.right;
            break;
        }

        switch (rotateAxis)
        {
        case 1:
            rotateDir = -transform.up;
            break;

        case 2:
            rotateDir = transform.up;
            break;
        }

        float MoveSpeedRand = Random.Range(MoveSpeed - MoveSpeedVariance, MoveSpeed + MoveSpeedVariance);
        float TurnSpeedRand = Random.Range(TurnSpeed - TurnSpeedVariance, TurnSpeed + TurnSpeedVariance);
        float TagMod        = Tag != "" && agent.gameObject.CompareTag(Tag) ? TagSpeedChange : 1f;

        rigidbody.AddForce(dirToGo * MoveSpeedRand * TagMod, ForceMode.VelocityChange);
        gameObject.transform.Rotate(rotateDir, Time.fixedDeltaTime * TurnSpeedRand);

        if (rigidbody.velocity.sqrMagnitude > MaxVelocity * MaxVelocity) // slow it down
        {
            rigidbody.velocity *= 0.95f;
        }

        if (agent.area.EventSystem != null)
        {
            agent.area.EventSystem.RaiseEvent(TransformEvent.Create(gameObject));
        }
    }