Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (isMoving)
        {
            // How long has it been since we last updated our position
            float distanceIncrement = this.moveRate * Time.deltaTime;
            // find out how far we should move
            // convert to T value 0...1
            this.currentDistanceAlongDubinPath += distanceIncrement;
            if (currentDistanceAlongDubinPath >= finalDistanceAlongDubinPath)
            {
                distanceIncrement             = currentDistanceAlongDubinPath - finalDistanceAlongDubinPath;
                currentDistanceAlongDubinPath = finalDistanceAlongDubinPath;
                isMoving = false;
            }
            else
            {
                this.CurrentMoveDistance -= distanceIncrement;
            }

            this.CurrentMoveDistance = Mathf.Max(0.0f, CurrentMoveDistance);

            DubinCSC currentDubin     = CurrentPath.path[this.currentDubinIdx];
            float    relativeDistance = currentDistanceAlongDubinPath - runningDubinDistanceTotal;

            if (relativeDistance > currentDubin.totalLength)
            {
                this.runningDubinDistanceTotal += currentDubin.totalLength;
                relativeDistance -= currentDubin.totalLength;

                currentDubinIdx++;
                currentDubin = this.currentPath.path[currentDubinIdx];
            }

            Vector3 nextPos;
            Vector3 nextDir;

            currentDubin.GetPositionAndHeadingFromDistance(relativeDistance, this.currentPath.turnRadius, out nextPos, out nextDir);

            // move to that spot.
            this.transform.position = nextPos;
            this.transform.forward  = this.CurrentPath.isReverse ? -nextDir : nextDir;

            gameEventSystem.RaiseEvent(GameEventType.ObjectPropertyChanged, this.gameObject, this.gameObject);

            // TODO:
            // Do something with tile grid?
            // Do we care for in motion stuff, or just the end position?

            if (!isMoving)
            {
                ////TODO: Do we really want to clear the entire, or just from the last point?
                //// in which case, we'd need to clip the dubin, basicaly....or repath
                //this.CurrentPath.path.Clear();
                this.CurrentPath.Clip(currentDistanceAlongDubinPath);
                gameEventSystem.RaiseEvent(GameEventType.PathChanged, this.gameObject, CurrentPath);
                gameEventSystem.RaiseEvent(GameEventType.MoveEnded, this.gameObject, CurrentPath);
            }
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (attacker != null && lookCamera != null)
        {
            // TODO:  Move the turret to the mouselook location...slowly
            MouseLook.LookRotation(transform, lookCamera.transform, lookCamera.fieldOfView / maxFoV);

            //TODO:  Kind of kludgey

            var ray = lookCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0.0f));
            gameEventSystem.RaiseEvent(GameEventType.TargetOrientationChanged, attacker.gameObject, ray);

            if (Input.GetAxis("Zoom") != 0)
            {
                float fov = targetFoV - (Input.GetAxis("Zoom") * sensitivityZ * Time.deltaTime * (targetFoV / minFoV));
                targetFoV = Mathf.Clamp(fov, minFoV, maxFoV);
            }

            if (Input.GetButton("Fire1")) // todo move to down?
            {
                // Fire the shot
                // leave attack mode
                // enter shot cam mode

                // TODO: Accuracy on shot, perhaps pass in here.

                bulletCamState.TargetProjectile = attacker.FireWeapon();



                var bulletCollider = bulletCamState.TargetProjectile.GetComponent <Collider>();
                foreach (var attackerCollider in attacker.GetComponentsInChildren <Collider>())
                {
                    Physics.IgnoreCollision(bulletCollider, attackerCollider);
                }

                playerController.ReplaceState(bulletCamState);
            }
            else if (Input.GetButton("Fire2"))
            {
                playerController.PopCurrentState();
            }
        }

        if (lookCamera.fieldOfView != targetFoV)
        {
            lookCamera.fieldOfView = Mathf.MoveTowards(lookCamera.fieldOfView, targetFoV, ZoomRate);
        }
    }
Exemplo n.º 3
0
    public void SetSpeed(Speed newSpeed)
    {
        // this.tileMoveable.turnRadius = this.TurnRadiusArray[(int)newSpeed];
        // this.tileMoveable.MaxMoveDistance = MovementPoints; // this.DistanceArray[(int)newSpeed];
        //this.tileMoveable.CurrentMoveDistance = tileMoveable.MaxMoveDistance;


        currentSpeed = newSpeed;

        this.tileMoveable.CurrentMoveDistance = CurrentDistance;
        this.tileMoveable.MaxMoveDistance     = CurrentDistance;
        gameEventSystem.RaiseEvent(GameEventType.SpeedChanged, this.gameObject, newSpeed);
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        // TODO:  Only active objects should turn....
        bool turretRotationChanged = false;

        if (turretToRotateHorizontal.localRotation.eulerAngles.y != targetHorzAngle)
        {
            float   horzAngle  = HorizontalTraverseDegreesPerSecond * Time.deltaTime;
            Vector3 localEuler = turretToRotateHorizontal.localRotation.eulerAngles;
            turretToRotateHorizontal.localRotation = Quaternion.Euler(
                localEuler.x,
                Mathf.MoveTowardsAngle(localEuler.y, targetHorzAngle, horzAngle),
                localEuler.z);

            //Quaternion.RotateTowards(turretToRotateHorizontal.localRotation, targetHorzRot, horzAngle);

            turretRotationChanged = true;
        }

        if (turretToRotateVertical.localRotation.eulerAngles.x != targetVerticalAngle)
        {
            float   vertAngle  = VerticalTraverseDegreesPerSecond * Time.deltaTime;
            Vector3 localEuler = turretToRotateVertical.localRotation.eulerAngles;
            turretToRotateVertical.localRotation = Quaternion.Euler(
                Mathf.MoveTowardsAngle(localEuler.x, targetVerticalAngle, vertAngle),
                localEuler.y,
                localEuler.z);
            //turretToRotateVertical.localRotation =
            //    Quaternion.RotateTowards(turretToRotateVertical.localRotation, targetVerticalRot, vertAngle);

            turretRotationChanged = true;
        }


        if (turretRotationChanged)
        {
            var muzzlePos = this.GetComponent <WeaponScript>().MuzzlePosition;
            var hitPoint  = FindHitPoint(new Ray(muzzlePos.position, muzzlePos.forward));

            // Let the UI know where the tank is actually pointing
            gameEventSystem.RaiseEvent(GameEventType.TurretOrientationChanged, this.gameObject, hitPoint);
        }
    }
 public override void OnInspectorGUI()
 {
     serializedObject.Update();
     base.OnInspectorGUI();
     // var layers = serializedObject.FindProperty("layers");
     // for (int i = 0; i < 32; i++)
     // {
     //     var property = layers.GetArrayElementAtIndex(i);
     //     layers.GetArrayElementAtIndex(i).stringValue = EditorGUILayout.TextField("Event Layer " + i, layers.GetArrayElementAtIndex(i).stringValue);
     // }
     // EditorGUILayout.PropertyField(serializedObject.FindProperty("current"));
     // EditorGUILayout.PropertyField(serializedObject.FindProperty("logging"));
     if (GUILayout.Button("Save"))
     {
         Save();
     }
     if (GUILayout.Button("Raise Event"))
     {
         gameEventSystem.RaiseEvent(gameEventSystem.current);
     }
     serializedObject.ApplyModifiedProperties();
 }
Exemplo n.º 6
0
 public void OnEndTurn_Clicked()
 {
     this.BroadcastMessage("OnEndTurn");
     gameEventSystem.RaiseEvent(GameEventType.TurnEnded, this.gameObject, this.gameObject);
 }
Exemplo n.º 7
0
    void OnCollisionEnter(Collision other)
    {
        var shell = other.gameObject.GetComponent <ShellScript>();

        hasCollided       = true;
        lastContactNormal = other.contacts[0].normal;
        lastContactPoint  = other.contacts[0].point;

        if (shell != null)
        {
            Debug.Log("I was hit by a shell! " + this.gameObject.name);

            // Get the current penetration
            float pen = shell.GetCurrentPenetration();

            float cosRadians = Vector3.Dot(other.contacts[0].normal, shell.transform.forward);

            // Note that WarT has a random ricochet chance depending on angle / shell type
            //  WoT has a always ricochet

            // TODO:  Add a richochet cancel is pen is 3x the armor
            if (Mathf.Abs(cosRadians) > kRicochetAngleInRadians)
            {
                Debug.Log("Richochet!"); // I should do something here...maybe adjust the forward to fake a ricochet?
                // I may not have to do jack, just let the physics handle it.
                shell.RemoveShell();
            }
            else
            {
                // adjust armor to the direction of impact
                float adjustedArmor = this.GetArmorValue(other.contacts[0]) / cosRadians;
                Debug.Log("Armor: " + Armor);
                Debug.Log("Adjusted Armor: " + adjustedArmor);

                float newPen = pen * Random.Range(kMinPen, kMaxPen);
                Debug.Log("Adjusted Pen By Random Amount:" + newPen);

                newPen -= adjustedArmor;

                if (newPen > Mathf.Epsilon)
                {
                    Debug.Log("Penetrated!");

                    //TODO: this could probably all go in the shell
                    shell.SetupPenetration(newPen, other.contacts[0].thisCollider, other.contacts[0].point);

                    // TODO:  I think i'm better off spawning a shell 'fragment' here instead.

                    gameEventSystem.RaiseEvent(GameEventType.SuccessfulArmorPenetration, this.gameObject, this);

                    // how to determine damage? Example: A track is hit, I guess i just raise an event to the TileMoveable
                    // that it got hti wtih a shell of type X, and it

                    StartHighlight();
                }
                else
                {
                    Debug.Log("Failed to penetrate");
                    shell.RemoveShell();
                }
            }
        }
    }
Exemplo n.º 8
0
 public void RemoveShell()
 {
     this.gameObject.layer = LayerMask.NameToLayer("NullLayer");
     gameEventSystem.RaiseEvent(GameEventType.BulletLifetimeOver, this.gameObject, this);
     DestroyObject(this.gameObject);
 }