Exemple #1
0
    public MyPhysics Physics;        //Physics Component
    //Used to Initialise Bullet
    public void Init(BulletInit Initiate)
    {
        //Get Components
        Physics        = GetComponent <MyPhysics>();        //Gets Physics component from object (Makes sure physics is up to date)
        Transformation = GetComponent <myTransformation>(); //Gets Transformation Component from object (Makes sure transformation is up to date)

        //Reset Timeout
        timeoutDestructor = 0;

        //Set Scale
        Transformation.Scale = new MyVector3(2, 2, 2);

        //Set Physical Mass
        Physics.Mass = Initiate.mass;

        //Set Rotation And Translation
        Transformation.Translation = Initiate.GunPosition;


        //Apply a force in the direction of the gun and times it by the firing speed
        Physics.Force += VectorMaths.EulerAnglesToDirection(new MyVector3(Initiate.GunRotation.x, -Initiate.GunRotation.y, 0)) * Initiate.FireSpeed;
        Physics.Bouncy = true;
        //Force Bullet to be alive
        Alive = true;
    }
    // Update is called once per frame
    void Update()
    {
        if (firsttime == false)
        {
            Transformation = GetComponent <myTransformation>();          //Gets the transformations
            Physics        = GetComponent <MyPhysics>();                 //Gets the physic Component
            Physics.Bouncy = true;                                       //Sets the objects to be dynamic
            Physics.Mass   = FindObjectOfType <Sniper>().Mass;           //sets mass to 1.01f
            Physics.Force  = new MyVector3(0, 0, 0);                     //Sets force to 0
            Physics.Force += VectorMaths.EulerAnglesToDirection(new MyVector3(Transformation.Rotation.x, -Transformation.Rotation.y, 0)) * FindObjectOfType <Sniper>().FireSpeed;
            ForceApplied   = Physics.Force;                              //Sets Force Applied to physics force
            firsttime      = true;                                       //Sets first time true

            Origin = Transformation.Translation;                         //Sets Origin to the position the object started at
        }
        Transformation.Scale = new MyVector3(20, 20, 20);                //Sets the scale of the object
        Transformation       = GetComponent <myTransformation>();        //Gets transformation component
        Physics     = GetComponent <MyPhysics>();                        //Gets the physic component
        DeltaTimer += Time.deltaTime;                                    //Increase Delta Timer by delta time
        float Distance = (Origin - Transformation.Translation).Length(); //Distance from Origin to Object as length

        if (DeltaTimer > 60)
        {
            Destroy(this.gameObject); //Destroy the game object
            Destroy(this);            //Destroy this component
        }
        if (Distance > 15000)
        {
            Destroy(this.gameObject); //Destroy the game object
            Destroy(this);            //Destroy this component
        }
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        Quaternion R = Quaternion.Euler(angle);

        transform.rotation = R;
        GetComponent <myTransformation>().Rotation = new MyVector3(angle);
        Quaternion t = new Quaternion(q.x, q.y, q.z, q.w);

        UnityRotation          = transform.rotation;
        UnityTargetOrientation = t * UnityRotation;
        UnityEulerAngle        = UnityTargetOrientation.eulerAngles;
        transform.rotation     = UnityTargetOrientation;
        UnityNewRotation       = transform.rotation;
        UnityNewEulerAngle     = UnityNewRotation.eulerAngles;
        transform.rotation     = UnityRotation;



        Rotation          = GetComponent <myTransformation>().GetRotation();
        TargetOrientation = q * Rotation;
        myTransformation Temp = GetComponent <myTransformation>();

        EulerAngle = Quat.QuatToEuler(TargetOrientation);
        Temp.SetRotation(TargetOrientation);

        NewRotation   = Temp.GetRotation();
        NewEulerAngle = Quat.QuatToEuler(NewRotation);
        GetComponent <myTransformation>().Rotation = new MyVector3(angle);
    }
Exemple #4
0
    // Update is called once per frame
    void Update()
    {
        Sniper sniper = FindObjectOfType <Sniper>();        //As there is only one player you can just find the sniper object

        Physics        = GetComponent <MyPhysics>();        //Gets Physics component from object (Makes sure physics is up to date)
        Transformation = GetComponent <myTransformation>(); //Gets Transformation Component from object (Makes sure transformation is up to date)

        //Checks if timer is more then 0.2, this stops explosions being instant
        if (timeoutDestructor > 0.2f)
        {
            //Checks if the player is creating an explosion
            if (sniper.Explosion == true)
            {
                //If physic object has collided run these scripts
                if (Physics.Collided == true)
                {
                    GameObject go = new GameObject("Explosion");           //Create a new invisble game object called explosion
                    go.AddComponent <Explosion>();                         //Add Explosion
                    go.AddComponent <myTransformation>();                  //Add Transformation

                    TransformationInit Temp;                               //Create an initiation structre for transformation
                    Temp.Translation    = this.Transformation.Translation; //Set translalation
                    Temp.Translation.y -= 20;                              //Decrease height, this makes the explosion more impactfull
                    Temp.Scale          = this.Transformation.Scale;       //Sets scale
                    Temp.Rotation       = this.Transformation.Rotation;    //sets rotation
                    go.GetComponent <myTransformation>().Initialise(Temp); //Sets the transformation to initation structure
                    timeoutDestructor = 10000;                             //Kill the bullet
                }
            }
        }
        //Add Delta Time TO timeout Destructor
        timeoutDestructor += Time.deltaTime;
    }
    // Update is called once per frame
    void Update()
    {
        myTransformation Transformation = GetComponent <myTransformation>();

        float CurRadius    = float.MinValue;
        float MinCurRadius = float.MaxValue;


        if (Transformation.ModelMaxExtent.x > CurRadius)
        {
            CurRadius = Transformation.ModelMaxExtent.x;
        }
        if (Transformation.ModelMaxExtent.y > CurRadius)
        {
            CurRadius = Transformation.ModelMaxExtent.y;
        }
        if (Transformation.ModelMaxExtent.z > CurRadius)
        {
            CurRadius = Transformation.ModelMaxExtent.z;
        }


        if (Transformation.ModelMinExtent.x < MinCurRadius)
        {
            MinCurRadius = Transformation.ModelMinExtent.x;
        }
        if (Transformation.ModelMinExtent.y < MinCurRadius)
        {
            MinCurRadius = Transformation.ModelMinExtent.y;
        }
        if (Transformation.ModelMaxExtent.z < MinCurRadius)
        {
            MinCurRadius = Transformation.ModelMinExtent.z;
        }
        float BiggestScale = float.MinValue;

        if (Transformation.Scale.x > BiggestScale)
        {
            BiggestScale = Transformation.Scale.x;
        }
        if (Transformation.Scale.y > BiggestScale)
        {
            BiggestScale = Transformation.Scale.y;
        }
        if (Transformation.Scale.z > BiggestScale)
        {
            BiggestScale = Transformation.Scale.z;
        }



        Radius  = CurRadius - MinCurRadius;
        Radius *= BiggestScale;
        Transformation.BoundObject = new BoundingCircle(Transformation.Translation, Radius);
        BoundingCircle Circle1 = Transformation.BoundObject as BoundingCircle;

        CentrePoint = Circle1.CentrePoint;
        Radius      = Circle1.Radius;
    }
    // Update is called once per frame
    void Update()
    {
        Angle += Time.deltaTime * 2;
        q      = new Quat(Angle, Axis);
        myTransformation Transformation = GetComponent <myTransformation>();

        Transformation.SetRotation(q);
    }
    void FixedUpdate()
    {
        ExplosionStrength = FindObjectOfType <ExplosionStrengthText>().slider.value;         //Set Strength to be slider value
        ExplosionRadius   = FindObjectOfType <ExplosionRadiusText>().slider.value;           //Set radius to be slider value
        //THIS IS HOW YOU DO GRAVITY BUT OPPOSITE THIS REPELS THE OBJECTS
        ExplosionBounds = new BoundingCircle(Transformation.Translation, ExplosionRadius);   //Set bounds of explosion
        Transformation  = GetComponent <myTransformation>();                                 //Get Transformation component of object
        BoundingCircle Bounds = new BoundingCircle(new MyVector3(0, 0, 0), ExplosionRadius); //Bounds Of explosion

        Bounds             = ExplosionBounds as BoundingCircle;                              //Set bounds to be xplosion bounds
        Bounds.CentrePoint = Transformation.Translation;                                     //Make sure centre point is position of expplosion

        Object = FindObjectsOfType <MyPhysics>();                                            //Find all physic objects
        for (int i = 0; i < Object.Length; i++)
        {
            if (Bounds.Intersects(Object[i].Transformation.BoundObject))
            {
                float Radius = float.MinValue; //Set radius to be minium value
                if (Object[i].Transformation.BoundObject is AABB)
                {
                    AABB Box1 = Object[i].Transformation.BoundObject as AABB; //Get the object collision box

                    if (Box1.MaxExtent.x > Radius)
                    {
                        Radius = Box1.MaxExtent.x; //Set radius to be max extent x
                    }
                    if (Box1.MaxExtent.y > Radius)
                    {
                        Radius = Box1.MaxExtent.y; //Set radius to be max extent y
                    }
                    if (Box1.MaxExtent.z > Radius)
                    {
                        Radius = Box1.MaxExtent.z; //Set radius to be max extent z
                    }
                }
                if (Object[i].Transformation.BoundObject is BoundingCircle)
                {
                    BoundingCircle Sphere1 = Object[i].Transformation.BoundObject as BoundingCircle; //Get the object bounding sphere
                    Radius = Sphere1.Radius;                                                         //Set radius to be object radius
                }

                ExplosionForce   = VectorMaths.VectorNormalized(Object[i].Transformation.Translation - Transformation.Translation) * ExplosionStrength; //Set force of explosion to be normalised of object postion - explosion position
                Object[i].Force += ExplosionForce;                                                                                                      //Increase object force by explosion force
                CentreOfMass     = Transformation.Translation;                                                                                          //SEt centre of mass to explosion point

                Distance   = Object[i].Transformation.Translation - Transformation.Translation;                                                         //Distance from object to explosion
                Normalised = VectorMaths.VectorNormalized(Distance);                                                                                    //Normalised Distance



                ImpactPoint       = Normalised * Radius;                                                        //Set impact point to be normalised * radius
                ExplosionTorque   = VectorMaths.VectorCrossProduct(ExplosionForce, CentreOfMass - ImpactPoint); //Toorque os the cross product of explosion force and centre of mass - impact point
                Object[i].torque += ExplosionTorque;                                                            //Torque is increaess by explosion torque
            }
        }
    }
Exemple #8
0
 public TargetSpawn TaretSpawner;    //Target controler
 void Start()
 {
     Transformation = GetComponent <myTransformation>();
     Transformation.Translation.y = 100;                 //Makes sure Height is high to stop floor collision
     Target.x = 0;                                       //Sets target x to 0
     Target.y = 0;                                       //Sets target x to 0
     Target.z = 0;                                       //Sets target z to 0
     NewPostion();                                       //Calls new position function
     Transformation.Scale = new MyVector3(100, 150, 10); //Sets scale of object to be 100, 150, 10
 }
    // Update is called once per frame
    void Update()
    {
        myTransformation Transformation = GetComponent <myTransformation>();

        float CurRadius    = float.MinValue;
        float MinCurRadius = float.MaxValue;


        if (Transformation.ModelMaxExtent.x > CurRadius)
        {
            CurRadius = Transformation.ModelMaxExtent.x;
        }

        if (Transformation.ModelMaxExtent.z > CurRadius)
        {
            CurRadius = Transformation.ModelMaxExtent.z;
        }


        if (Transformation.ModelMinExtent.x < MinCurRadius)
        {
            MinCurRadius = Transformation.ModelMinExtent.x;
        }

        if (Transformation.ModelMaxExtent.z < MinCurRadius)
        {
            MinCurRadius = Transformation.ModelMinExtent.z;
        }
        float BiggestScale = float.MinValue;

        if (Transformation.Scale.x > BiggestScale)
        {
            BiggestScale = Transformation.Scale.x;
        }

        if (Transformation.Scale.z > BiggestScale)
        {
            BiggestScale = Transformation.Scale.z;
        }



        Radius  = CurRadius - MinCurRadius;
        Radius *= BiggestScale;


        Transformation.BoundObject = new BoundingCapsule(Transformation.Translation + (Transformation.Scale * Transformation.ModelMinExtent),
                                                         Transformation.Translation + (Transformation.Scale * Transformation.ModelMaxExtent),
                                                         Radius);
        BoundingCapsule Capsule2 = Transformation.BoundObject as BoundingCapsule;

        Min = Capsule2.A;
        Max = Capsule2.B;
    }
 // Update is called once per frame
 void Update()
 {
     ExplosionStrength = FindObjectOfType <ExplosionStrengthText>().slider.value; //Set Strength to be slider value
     ExplosionRadius   = FindObjectOfType <ExplosionRadiusText>().slider.value;   //Set radius to be slider value
     timer            += Time.deltaTime;                                          //Increase timer by delta time
     if (timer >= 2)
     {
         Destroy(this.gameObject);                       //Destroy Explosion game object
         Destroy(this);                                  //Destroy this component
     }
     Transformation = GetComponent <myTransformation>(); //Get Transformation Componenet
 }
Exemple #11
0
    // Update is called once per frame
    void Update()
    {
        MyPhysics physics = GetComponent <MyPhysics>(); //Get and store the physics component

        timer += Time.deltaTime;                        //Add delta time to timer
        if (timer >= 3)
        {
            if (physics.Collided == true)
            {
                Alive = false; //Set Alive to falsez
            }
        }

        Transformation = GetComponent <myTransformation>(); //Get the object transformation and store it


        if (MyVector3.Length(Target - Transformation.Translation) < 5)
        {
            Transformation.Translation = Target; //Set translation to be target
        }
        else
        {
            if (MyVector3.Length(Target - Transformation.Translation) > 5)
            {
                Transformation.Translation = Target; //Set translation to be target
            }
            if (MyVector3.Length(Target - Transformation.Translation) > 50)
            {
                Speed = 5; //Speed set to 5
            }
            if (MyVector3.Length(Target - Transformation.Translation) > 500)
            {
                Speed = 10; //Speed set to 10
            }
            if (MyVector3.Length(Target - Transformation.Translation) > 5000)
            {
                Speed = 50; //Speed set to 50
            }
            if (MyVector3.Length(Target - Transformation.Translation) > 50000)
            {
                Speed = 100;                                             //Speed set to 100
            }
            MyVector3 Direction = (Target - Transformation.Translation); //Direction = Target - Transllation
            Direction = VectorMaths.VectorNormalized(Direction);         //Direction is equal to direction normalised
            MyVector3 Velocity = Direction * Speed;                      //Velocity = direction * speed
            Transformation.Translation += Velocity;                      //Add Velocity to current translation
        }
    }
    // Update is called once per frame
    void Update()
    {
        myTransformation TempoaryTransformation = GetComponent <myTransformation>();


        MinExtent = TempoaryTransformation.Translation + (TempoaryTransformation.Scale * TempoaryTransformation.ModelMinExtent);
        MaxExtent = TempoaryTransformation.Translation + (TempoaryTransformation.Scale * TempoaryTransformation.ModelMaxExtent);
        TempoaryTransformation.BoundObject = new AABB(MinExtent, MaxExtent);
        AABB Box1 = TempoaryTransformation.BoundObject as AABB;

        Box1.Half   = (Box1.MaxExtent - Box1.MinExtent) * 0.5f;
        Box1.Centre = Box1.Half + Box1.MinExtent;
        MinExtent   = Box1.MinExtent;
        MaxExtent   = Box1.MaxExtent;
        Centre      = Box1.Centre;
        Half        = Box1.Half;
    }
    public float Distance;                  //Distance from player to spawner
    void CreateCube()
    {
        Transformation = GetComponent <myTransformation>();                          //Gets Transfion Component of object
        GameObject go = Instantiate(cube, new Vector3(0, 0, 0), transform.rotation); //Creates Game Object

        go.name = "Moving Target";                                                   //Sets name of object
        go.AddComponent <myTransformation>();                                        //Add Transformation component
        go.AddComponent <BoxUpdater>();                                              //Add box updater component
        TransformationInit Temp;                                                     //Initalisation Structure

        Temp.Translation = Transformation.Translation;                               //Rotation of Translation
        Temp.Rotation    = Transformation.Rotation;                                  //Rotation of Object
        Temp.Scale       = new MyVector3(2, 2, 2);                                   //Set scale to be 2,2,2
        go.GetComponent <myTransformation>().Initialise(Temp);                       //Initialise Transformation with initalise struct
        go.AddComponent <MyPhysics>();                                               //Add Physics Component

        go.AddComponent <MovingTarget>();                                            //Add moving target component
    }
Exemple #14
0
    // Update is called once per frame
    void Update()
    {
        Camera AlphaCam;

        AlphaCam = GetComponent <Camera>();
        myTransformation Focus       = SFocus;
        MyVector3        Camera      = new MyVector3(Focus.Rotation.x, Focus.Rotation.y, Focus.Rotation.z);
        MyVector3        CameraInRad = new MyVector3();

        CameraInRad.x = VectorMaths.Deg2Rad(Camera.x);
        CameraInRad.y = VectorMaths.Deg2Rad(Camera.y);
        CameraInRad.z = VectorMaths.Deg2Rad(Camera.z);
        Quat Temp = Quat.EulerToQuat(CameraInRad);

        AlphaCam.transform.position = new Vector3(Focus.Translation.x, Focus.Translation.y, Focus.Translation.z);
        AlphaCam.transform.rotation = new Quaternion(
            -Temp.x,
            -Temp.y,
            Temp.z,
            Temp.w);
    }
Exemple #15
0
    void Fire()
    {
        Transformation = GetComponent <myTransformation>();                                 //Get transformation componenet
        GameObject go = Instantiate(BulletModel, new Vector3(0, 0, 0), transform.rotation); //Create game object

        go.name = "Bullet";                                                                 //Change name of game object to be bullet
        go.AddComponent <myTransformation>();                                               //Add transformation componet
        go.AddComponent <BoxUpdater>();                                                     //Add box collider component
        go.AddComponent <MyPhysics>();                                                      //Add physics component
        go.AddComponent <Bullet>();                                                         //Add Bullet component
        BulletInit Temp;                                                                    //Initialise structure

        Temp.FireSpeed   = FireSpeed;                                                       //Set firing speed
        Temp.mass        = Mass;                                                            //Set mass
        GunPosition      = Transformation.Translation + GunOffset;                          //Set gun postion to be offset of the players location
        Temp.GunPosition = GunPosition;                                                     //Set postion of bullet
        Temp.GunRotation = Transformation.Rotation;                                         //Set rotation of bullet
        go.GetComponent <Bullet>().Init(Temp);                                              //Intialise bullet with init structure
        Bullets.Add(go.GetComponent <Bullet>());                                            //add bullet component to bullet list
        BulletHandler.Add(go);                                                              //Add game object to bullet game object list
    }
    void FixedUpdate()
    {
        Collided       = false;                             //Set collided to false
        Transformation = GetComponent <myTransformation>(); //Get transformation component of object
        if (Transformation.Translation.y < -50)
        {
            Transformation.Translation.y = 50; //If object has fallen through level reset that object
        }
        if (PhysicObjectHandler != null)
        {
            Gravity = PhysicObjectHandler.Gravity; //Set gravity to be handler gravity (Singleton)
        }
        if (Dynamic == true || Bouncy == true)
        {
            WeightForce  = Force + (Gravity * Mass); //set weight force to be force + gravtiy * mass
            Force       += Gravity * Mass;           //Increase force by gravity * mass
            Acceleration = Force / Mass;             //Set Acceleration to be force / mass


            Velocity           += Acceleration * Time.fixedDeltaTime;        //Increase velocity by acceleration * fixed delta time
            Force               = new MyVector3(0, 0, 0);                    //sets force to 0 otherwise a force will constantly be applied ot the object
            AngularAcceleration = torque / Inertia;                          //set rotational acceleration to be torque / intertia
            AngularVelocity    += AngularAcceleration * Time.fixedDeltaTime; //Increase angular velocity by angular acceleration * fixed delta time
            torque              = new MyVector3(0, 0, 0);                    //Set torque to 0 otherwise object will always rotate
        }

        if (PhysicObjectHandler != null)
        {
            for (int i = 0; i < PhysicObjectHandler.PhysicHandle.Count; i++)
            {
                if (ObjectId != PhysicObjectHandler.PhysicHandle[i].ObjectId)
                {
                    if (Transformation.BoundObject.Intersects(PhysicObjectHandler.PhysicHandle[i].Transformation.BoundObject))
                    {
                        Collided = true;                                                                                                                      //Set collided to true
                        Transformation.BoundObject.CollisionResolution(PhysicObjectHandler.PhysicHandle[i].Transformation.BoundObject, out Normal, out Push); //Get collision resoloutiuon data from the collision
                        if (Bouncy == true)
                        {
                            Transformation.Translation += Normal * (Push + 0.0000001639f);          //Push the object by normal * (Push + 0.0000001639f) this stops to object getting stuck on terrain

                            Velocity = new MyVector3(-Velocity.x, -Velocity.y, -Velocity.z) * 0.9f; //Inverse velocity and times it by 0.9
                        }
                        if (Dynamic == true)
                        {
                            Transformation.Translation += Normal * (Push + 0.0000001639f); //Push the object by normal * (Push + 0.0000001639f) this stops to object getting stuck on terrain
                            Velocity = new MyVector3(0, 0, 0);                             //Set velocity to be 0
                        }
                    }
                }
            }
        }
        Transformation.Translation += Velocity * Time.deltaTime; //Increase translation by velocity * delta time



        if (player == false)
        {
            Quat  q     = new Quat();                                                       //Create Q
            float avMag = (AngularVelocity * Time.fixedDeltaTime).Length();                 //set av mg to be the length of  angular velocity * fixed time
            q.w = Mathf.Cos(avMag / 2);                                                     //set w to be Cos of av mag /2
            q.x = Mathf.Sin(avMag / 2) * (AngularVelocity * Time.fixedDeltaTime).x / avMag; //set x to be sin of av mag / 2  * angular velocity x * fixed time / avg mag
            q.y = Mathf.Sin(avMag / 2) * (AngularVelocity * Time.fixedDeltaTime).y / avMag; //set y to be sin of av mag / 2  * angular velocity y * fixed time / avg mag
            q.z = Mathf.Sin(avMag / 2) * (AngularVelocity * Time.fixedDeltaTime).z / avMag; //set z to be sin of av mag / 2  * angular velocity z * fixed time / avg mag
            Quat TargetOrienation = q * Transformation.GetRotation();                       //Multiply new rotation by current rotation of object

            Transformation.SetRotation(TargetOrienation);                                   //Set rotation of object to new rotation
            AngularVelocity *= (Time.deltaTime * 2);                                        //Multiply Angular Velocity by Delta time * 2
        }
    }
Exemple #17
0
    // Update is called once per frame
    void Update()
    {
        Player = GetComponent <Sniper>();
        myTransformation Ptransform = Player.GetComponent <myTransformation>();

        Distance         = Ptransform.Translation - OriginPoint;
        DistanceToRadius = Distance.Length();

        if (CluterAmmount != CluterAmmountLast || DistanceToRadius >= 250)
        {
            OriginPoint = new MyVector3(Ptransform.Translation.x, Ptransform.Translation.y, Ptransform.Translation.z);

            if (Ambient != null)
            {
                if (Ambient.Count >= 0)
                {
                    for (int i = 0; i < Ambient.Count; i++)
                    {
                        Destroy(Ambient[i]);
                    }
                }
            }
            Ambient.Clear();

            for (int i = 0; i < CluterAmmount; i++)
            {
                radius = Random.Range(0, 5000.0f);
                int x = Random.Range(0, Models.Count);

                TransformationInit Temp;
                Temp.Scale = new MyVector3(1, 1, 1);
                GameObject  go = Instantiate(Models[x], transform.position, transform.rotation);
                PhysicsInit physicsInit;
                physicsInit.Bouncy  = false;
                physicsInit.Dynamic = true;
                physicsInit.Mass    = Random.Range(1.0f, 100.0f);
                go.AddComponent <myTransformation>();

                float X, Y, Z;
                X = Random.Range(1, 10);
                Y = Random.Range(1, 10);
                Z = Random.Range(1, 10);
                if (x == 0)
                {
                    go.name    = "Box " + i;
                    Temp.Scale = new MyVector3(X, Y, Z);
                    go.AddComponent <BoxUpdater>();
                }

                if (x == 1)
                {
                    go.name    = "Box " + i;
                    Temp.Scale = new MyVector3(X, Y, Y);
                    go.AddComponent <BoxUpdater>();
                }
                if (x == 2)
                {
                    go.name    = "Sphere " + i;
                    Temp.Scale = new MyVector3(X, X, X);
                    go.AddComponent <SphereUpdate>();
                    physicsInit.Bouncy  = true;
                    physicsInit.Dynamic = false;
                }


                Temp.Translation   = new MyVector3(Random.Range(-1.0f, 1.0f), 6, Random.Range(-1.0f, 1.0f));
                Temp.Translation   = VectorMaths.VectorNormalized(Temp.Translation);
                Temp.Translation  *= radius;
                Temp.Translation  += OriginPoint;
                Temp.Translation.y = 16;
                //RandomVector(radius);
                Temp.Rotation = new MyVector3();
                go.AddComponent <MyPhysics>();
                go.GetComponent <MyPhysics>().Initialise(physicsInit);

                go.GetComponent <myTransformation>().Initialise(Temp);

                Ambient.Add(go);
            }
        }
        CluterAmmountLast = CluterAmmount;
    }
    // Update is called once per frame
    void Update()
    {
        ForwardDirection = VectorMaths.EulerAnglesToDirection(new MyVector2(PITCH, YAW));  //Get Forward direction of  player
        RightDirection   = VectorMaths.VectorCrossProduct(MyVector3.up, ForwardDirection); //Get cross product of up and forward direction
        RightDirection   = VectorMaths.VectorNormalized(RightDirection);                   //Normalise Right direction so if the player looks directly up they can still move left and right

        if (FindObjectOfType <Sniper>().UI.enabled == false)
        {
            if (Playercontrol == true)
            {
                if (Input.GetKey(KeyCode.R))
                {
                    Playercontrol = false; //sets player control to false
                }

                if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
                {
                    Transformation.Translation += ForwardDirection * 2; //Increase force by Forward direction * 1000
                }
                if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
                {
                    Transformation.Translation += RightDirection * 2; //Increase force by Right direction * 1000
                }
                if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))
                {
                    Transformation.Translation -= ForwardDirection * 2;  //decrease force by forward direction * 1000
                }
                if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
                {
                    Transformation.Translation -= RightDirection * 2; //decrease force by right direction * 1000
                }
                if (Input.GetKey(KeyCode.Space))
                {
                    Transformation.Translation += new MyVector3(0, 1, 0) * 2; //Increase force by Up * 100
                }
                if (Input.GetKey(KeyCode.LeftAlt))
                {
                    Transformation.Translation -= new MyVector3(0, 1, 0) * 2;            //Increase force by Up * 100
                }
                PITCH += -Input.GetAxis("Mouse Y");                                      //Increases pitch by mouse rotation y
                YAW   += Input.GetAxis("Mouse X");                                       //Increase Yaw by Mouse x

                PITCH = Mathf.Clamp(PITCH, -90, 90);                                     //Clamp the players look down and up rotatiopn
                FindObjectOfType <CamLock>().SFocus = GetComponent <myTransformation>(); //Sets the cameera focus to spawner transformation
            }
            else
            {
                FindObjectOfType <CamLock>().SFocus = FindObjectOfType <Sniper>().Transformation; //Set the camera focus to sniper transformation
            }
            Transformation = GetComponent <myTransformation>();                                   //Get transformation of object
            Timer         += Time.deltaTime;                                                      //Increases timer by delta tim
            if (Timer >= timebetweenobjects)
            {
                if (Playercontrol == true)
                {
                    if (Input.GetMouseButton(0))
                    {
                        CreateCube(); //Creates a target
                        Timer = 0;    //Sets timer to 0
                    }
                }
                else
                {
                    CreateCube(); //Creates a target
                    Timer = 0;    //Sets timer to 0
                }
            }
            Distance = (FindObjectOfType <Sniper>().Transformation.Translation - Transformation.Translation).Length(); //Gets the distance between the sniper and the object
            if (Distance < 1000)
            {
                if (Input.GetKey(KeyCode.E))
                {
                    Playercontrol = true; //Allows the player to control the target spawner
                }
            }
            Transformation.Rotation = new MyVector3(-PITCH, -YAW, 0); //Sets Rotation to be inverse of pitch and yaw, for some reason unity has their mouse input set weirdly
        }
    }
Exemple #19
0
    void Update()
    {
        if (FindObjectOfType <SpawnMovingTarget>().Playercontrol == false)
        {
            FireSpeed               = ForceSlider.value;                                              //fireing speed is equal to slider value
            Mass                    = MassSlider.value;                                               //mass is equal to slider value
            Transformation          = GetComponent <myTransformation>();                              //Get Transformatio component
            Transformation.Rotation = new MyVector3(-PITCH, -YAW, 0);                                 //Set rotation to be inverse of pitch and yaw
            physics                 = GetComponent <MyPhysics>();                                     //Get physic component
            physics.player          = true;                                                           //Set player to true
            ForwardDirection        = VectorMaths.EulerAnglesToDirection(new MyVector2(PITCH, YAW));  //Convert pitch and yaw into a direction
            RightDirection          = VectorMaths.VectorCrossProduct(MyVector3.up, ForwardDirection); //Get cross product of up and forward direction
            RightDirection          = VectorMaths.VectorNormalized(RightDirection);                   //Normalise Right direction so if the player looks directly up they can still move left and right

            if (Transformation.Translation.y > 100)
            {
                physics.Force.y -= 100; //Decrease force by100
            }
            if (Transformation.Translation.y > 1000)
            {
                physics.Force.y -= 500; //Decrease Force y by 500
            }

            GunOffset   = RightDirection * 2;                     //Set gun offset to the right of the player
            GunPosition = Transformation.Translation + GunOffset; //Offet player postition by gun offset and set that value to gun positon


            PITCH += -Input.GetAxis("Mouse Y");   //Increase pitch by mouse y axis
            YAW   += Input.GetAxis("Mouse X");    //Increase yaw by mouse x axis
            PITCH  = Mathf.Clamp(PITCH, -90, 90); //Clamp pitch
            if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
            {
                physics.Force += ForwardDirection * 1000; //Increase force by Forward direction * 1000
            }
            if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
            {
                physics.Force += RightDirection * 1000; //Increase force by Right direction * 1000
            }
            if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))
            {
                physics.Force -= ForwardDirection * 1000;  //decrease force by forward direction * 1000
            }
            if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
            {
                physics.Force -= RightDirection * 1000; //decrease force by right direction * 1000
            }
            if (Input.GetKey(KeyCode.Space))
            {
                physics.Force += new MyVector3(0, 1, 0) * 100;        //Increase force by Up * 100
            }
            Transformation.Rotation = new MyVector3(-PITCH, -YAW, 0); //Set rotation to be inverse of pitch and yaw

            if (Bullets.Count > 0)
            {
                for (int i = 0; i < Bullets.Count; i++)
                {
                    if (Bullets[i].GetComponent <Bullet>().Alive == false)
                    {
                        Destroy(Bullets[i]);                    //Destroy bullet script
                        Bullets.Remove(Bullets[i]);             //Remove bullet script from list
                        Destroy(BulletHandler[i]);              //Destroy game object
                        BulletHandler.Remove(BulletHandler[i]); //Remove bullet game object from list
                    }
                    if (Bullets[i].GetComponent <Bullet>().timeoutDestructor >= 50)
                    {
                        Destroy(Bullets[i]);                    //Destroy bullet script
                        Bullets.Remove(Bullets[i]);             //Remove bullet script from list
                        Destroy(BulletHandler[i]);              //Destroy game object
                        BulletHandler.Remove(BulletHandler[i]); //Remove bullet game object from list
                    }
                }
            }
            Bolttimer -= Time.deltaTime; //Decrease bolttimer by delta time
            if (UI.enabled == false)
            {
                if (Bolttimer < 0)
                {
                    if (Input.GetMouseButton(0))
                    {
                        Fire();        //Call fire function
                        Bolttimer = 1; //Set bolt timer to be 1
                    }
                }
            }
            Transformation.Rotation = new MyVector3(-PITCH, -YAW, 0); //Set rotation to be inverse of pitch and yaw
        }
    }
Exemple #20
0
    // Update is called once per frame
    void Update()
    {
        myTransformation TempoaryTransformation = GetComponent <myTransformation>();

        TempoaryTransformation.Translation.x += 0.5f * Time.deltaTime;
    }