Esempio n. 1
0
    //----------------------------------------------------------------------------------------------------------------
    // Update is called once per frame

    void Update()
    {
        if (ctunity == null || ctclient == null)
        {
            Debug.Log(name + ", oops no ctunity/ctlient!");
            return;        // async
        }
        if (!ctunity.activePlayer(gameObject))
        {
            return;
        }

        launchInterval = ctclient.getCustom("dt", launchInterval);

        stopWatch += Time.deltaTime;
        if (stopWatch >= launchInterval)
        {
            String missile = ctclient.getCustom("M", Missile);  // optional custom missile
            Ilaunch = ctclient.getCustom("N", Ilaunch);
            Nlaunch = ctclient.getCustom("Nmax", Nlaunch);
            //           Debug.Log(name + ": Nlaunch: " + Nlaunch+", launchInterval: "+launchInterval);

            if (Nlaunch != 0 && Ilaunch >= Nlaunch)
            {
                return;
            }

            ctunity.deployInventory(missile, CTunity.fullName(gameObject) + "/R-" + Ilaunch);
            Ilaunch++;
            ctclient.putCustom("N", Ilaunch);

            stopWatch = 0;
        }
    }
Esempio n. 2
0
    void OnGUI()
    {
        Event m_Event = Event.current;

        if (m_Event.button != 0)
        {
            return;                                         // only check left-mouse button?
        }
        if (!ctunity.activePlayer(gameObject))
        {
            return;
        }

        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;                                                        // no deal if clicking on UI element
        }
        if ((m_Event.type == EventType.MouseDown && m_Event.clickCount == 2)

            /* ||  (m_Event.button == 1 && m_Event.type == EventType.MouseDown )
             * /* || (m_Event.type == EventType.MouseDrag) */)
        {
            RaycastHit hit;
            Ray        ray = mainCamera.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, maxDistance))
            {
                if (hit.collider.gameObject == gameObject)  // double click delete target
                {
                    Debug.Log(name + " Buh Bye");
                    ctunity.clearObject(gameObject);
                    return;
                }

                if (hit.collider.gameObject.GetComponent <CTclient>() == null)    // no target CTclient player objects
                {
                    targetPos = hit.point;
                }
                // Debug.Log("SET targetPos: " + targetPos + ", targetObj: " + CTunity.fullName(targetObj));
                // GameObject.Find("Main Camera").GetComponent<maxCamera>().setTarget(hit.transform);
            }
            m_Event.Use();
        }
    }
Esempio n. 3
0
    //----------------------------------------------------------------------------------------------------------------
    public Boolean isLocalControl()
    {
        if (ctunity == null)
        {
            return(false);                  // async?
        }
        Boolean ilc = isRogue || ctunity.activePlayer(gameObject);

        return(ilc);
    }
Esempio n. 4
0
    //----------------------------------------------------------------------------------------------------------------
    // detect triggers

    void OnTriggerEnter(Collider collider)
    {
        if (debug)
        {
            Debug.Log(CTunity.fullName(gameObject) + ", Trigger with: " + collider.name);
        }

        if (!showHP)
        {
            return;
        }
        ScoreBoard tkso = collider.gameObject.GetComponent <ScoreBoard>();

        //        if(tkso != null) Debug.Log("new kso.ATK: " + tkso.ATK + ", thisCollider: " + thisCollider);

        if (tkso != null && ctunity.activePlayer(gameObject) && !ctunity.localPlayer(collider.gameObject))
        {
            kso          = tkso;
            thisCollider = collider;
            targetScale  = transform.localScale;
            stopWatch    = damageInterval;  // quick hit to start
        }
    }
Esempio n. 5
0
    //----------------------------------------------------------------------------------------------------------------
    // Update is called once per frame
    void FixedUpdate()
    {
        if (rb == null)             // init async?
        {
            rb = GetComponent <Rigidbody>();

            // start with velocity of grandparent (?)
            if (rb != null)
            {
                Rigidbody pprb = transform.parent.transform.parent.gameObject.GetComponent <Rigidbody>();
                if (pprb != null)
                {
                    rb.velocity = pprb.velocity;
                }
            }
        }
        if (!ctunity.activePlayer(gameObject))
        {
            return;
        }

        // save fuel and flightTime with CT
        float fuel       = ctclient.getCustom("Fuel", fuelTime);
        float flightTime = ctclient.getCustom("Age", 0f);

//        Debug.Log(CTunity.fullName(gameObject) + ", fuel: " + fuel + ", fueltime: " + fuelTime+", flightTime: "+flightTime);
        fuel -= Time.deltaTime;         // fuel units = RT sec
        if (fuel < 0)
        {
            fuel = 0;
        }
        flightTime += Time.deltaTime;

        ctclient.putCustom("Fuel", fuel.ToString("0.00"));
        ctclient.putCustom("Age", flightTime.ToString("0.00"));
        if (fuel > 0)
        {
            float noiseX = (float)random.NextDouble() * wobbleFactor;               // bit of uncertainty so rockets don't perfectly "stack"
            float noiseZ = (float)random.NextDouble() * wobbleFactor;
            rb.AddRelativeForce(new Vector3(noiseX, 1f, noiseZ) * ForceFactor);
        }
        else if (flightTime > boomTime)
        {
//			Debug.Log(name + ": BOOM!");
            ctunity.clearObject(gameObject);
        }
    }
Esempio n. 6
0
    void Update()
    {
        if (!ctunity.activePlayer(gameObject))
        {
            return;                                              // notta
        }
        stopWatch += Time.deltaTime;
        if (stopWatch >= UpdateInterval)
        {
            stopWatch = 0f;

            float xrand = speedFactor * (float)(random.Next(-95, 95)) / 10F;
            float yrand = speedFactor * (float)(random.Next(-95, 95)) / 10F;
            float zrand = speedFactor * (float)(random.Next(-95, 95)) / 10F;
            newPos = transform.localPosition + new Vector3(xrand, zrand, yrand);

            newPos.x = Mathf.Clamp(newPos.x, -rangeLimit, rangeLimit);
            newPos.y = Mathf.Clamp(newPos.y, 0f, rangeLimit / 4f);                  // was /2f
            newPos.z = Mathf.Clamp(newPos.z, -rangeLimit, rangeLimit);
        }

//		transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime);
        transform.localPosition = Vector3.SmoothDamp(transform.localPosition, newPos, ref velocity, 2f * UpdateInterval);
    }
Esempio n. 7
0
    //----------------------------------------------------------------------------------------------------------------
    // push player around using forces; let in-game physics decide where it goes

    //	void Update()
    void FixedUpdate()          // fixed update for consistent force-application
    {
        if (!ctunity.activePlayer(gameObject))
        {
            return;
        }

        float moveHorizontal = Input.GetAxis("Horizontal"); // Right Left arrow keys +/- 1
        float moveVertical   = Input.GetAxis("Vertical");   // Up Down arrow keys
        // if (moveHorizontal == 0 && moveVertical == 0) return;   // notta

        Transform leader = null;

        if (followLeader
//            && (moveHorizontal == 0 && moveVertical == 0)
            )
        {
            if (targetObject == null)
            {
                targetObject = GameObject.Find(ctunity.Player + "/Base/Target");
            }
            //          GameObject tgo = GameObject.Find(ctunity.Player + "/Base/Target");
            if (targetObject != null && targetObject != gameObject)
            {
                leader = targetObject.transform;
                //   Debug.Log(CTunity.fullName(gameObject) + ", myleader: " + CTunity.fullName(targetObject));
            }
        }

        rb.angularVelocity = Vector3.zero;      // no spinning
        float liftforce = liftForce;

        if (/* moveHorizontal == 0 && */ moveVertical == 0)
        {
            liftforce = 0F;
        }

        // move in XY plane
        Vector3 movement;

        if (isVehicle)                // push in player-forward direction
        {
            if (leader != null)
            {
                transform.LookAt(leader.transform);
            }

            movement = new Vector3(0f, 0f, moveVertical);
            movement = transform.rotation * movement;               // align force to direction of player object

            float fwdVelocity = Vector3.Dot(rb.velocity, transform.forward);
            if (moveVertical <= 0)
            {
                liftforce = liftForce * fwdVelocity / maxSpeed;                     // lift ~ speed
            }
            if (fwdVelocity <= 0F)
            {
                liftforce   = 0F;
                rb.velocity = new Vector3(0F, rb.velocity.y, 0F);   // falling...
            }

            rb.AddTorque(transform.up * TorqueFactor * moveHorizontal);                    // twist and turn...

            Quaternion targetRotation = Quaternion.Euler(0F, transform.eulerAngles.y, 0F); // level off:
            transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime * 5F);
        }
        else                            // push in camera-look direction
        {
            movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
            if (leader != null)
            {
                transform.LookAt(leader);
                movement = transform.forward;
//                Debug.Log("lookat leader: "+leader.transform.position);
            }
            else
            {
                movement = mainCamera.transform.rotation * movement;   // align force to direction of camera
            }

            if (moveVertical >= 0)      // no spin in reverse
            {
                // rotate in direction of motion (go flat if slow/stopped or unpowered)
                Quaternion targetRotation;
                if (rb.velocity.magnitude > 0.1F /* && liftforce>0 */)
                {
                    targetRotation = baseRotation * Quaternion.LookRotation(rb.velocity);
                }
                else
                {
                    targetRotation = Quaternion.Euler(0F, transform.rotation.eulerAngles.y, 0F);
                }

                transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime * 2F);
            }
        }

        movement.y = 0F;
        movement.Normalize();
        movement   = movement * ForceFactor;
        movement.y = 10f * liftforce;               // nominal scaling?
        rb.AddForce(movement);                      // scaled, normalized

        // limit max speed
        if (rb.velocity.magnitude > maxSpeed)
        {
            Vector3 newVelocity = rb.velocity.normalized;
            newVelocity *= maxSpeed;
            rb.velocity  = newVelocity;
        }
    }