Exemplo n.º 1
0
        public void RpcInit(BallType type, ControlType ctrlType, int characterId, string nickname)
        {
            this.type        = type;
            this.ctrlType    = ctrlType;
            this.characterId = characterId;
            this.nickname    = nickname;


            Debug.Log("We re running RPCInit character is _ " + this.characterId);

            Up = Vector3.up;

            //Set up drifty smoke
            smoke            = Instantiate(prefabs.Smoke);
            smoke.target     = this;
            smoke.DriftAudio = sounds.Brake;

            //Grab reference to Rigidbody
            rb = GetComponent <Rigidbody>();
            //Set angular velocity (This is necessary for fast)
            rb.maxAngularVelocity = 1000f;

            //Set object name
            gameObject.name = nickname;

            //Set character
            if (CharacterId >= 0 && CharacterId < Data.ActiveData.Characters.Length)
            {
                SetCharacter(Data.ActiveData.Characters[CharacterId]);
            }

            //Create objects and components based on ball type
            if (type == BallType.Player && cameraBall == null && isLocalPlayer)
            {
                OmniCamera newCam = Instantiate(prefabs.Camera);
                newCam.Target   = rb;
                newCam.CtrlType = ctrlType;
                PivotCamera oldCam = Instantiate(prefabs.OldCamera);
                oldCam.Target   = rb;
                oldCam.CtrlType = ctrlType;

                //Create camera
                if (Data.ActiveData.GameSettings.useOldControls)
                {
                    cameraBall = oldCam;
                    newCam.gameObject.SetActive(false);

                    ((PivotCamera)cameraBall).UseMouse = ctrlType == ControlType.Keyboard;
                }
                else
                {
                    cameraBall = newCam;
                    oldCam.gameObject.SetActive(false);
                }
                cameraBall.Target   = rb;
                cameraBall.CtrlType = ctrlType;

                if (CameraCreatedEvent != null)
                {
                    CameraCreatedEvent(this, new CameraCreationArgs(cameraBall, oldCam.gameObject, newCam.gameObject));
                }
            }
            if (type == BallType.LobbyPlayer)
            {
                //Make the lobby camera follow this ball
                var cam = FindObjectOfType <LobbyCamera>();
                if (cam)
                {
                    cam.AddBall(this);
                }
            }
            if ((type == BallType.Player || type == BallType.LobbyPlayer && isLocalPlayer) && input == null)
            {
                //Create input component
                input = gameObject.AddComponent <BallControlInput>();
            }
            if (type == BallType.AI)
            {
                //Create AI component
                var ai = gameObject.AddComponent <BallControlAI>();
                ai.pathToFollow = FindObjectOfType <Path>();

                //Create target for the AI
                AITarget pFollower = Instantiate(prefabs.AiTarget);
                pFollower.GetComponent <PathFollower>().path = ai.pathToFollow;
                pFollower.stupidness = ai.stupidness;
                pFollower.GetComponent <Patroller>().target = gameObject;
                ai.target = pFollower;
            }

            if (!isServer)
            {
            }
        }
Exemplo n.º 2
0
        private void Start()
        {
            if (!isLocalPlayer && !isServer)
            {
                Up = Vector3.up;
                //Set up drifty smoke
//	            smoke = Instantiate(prefabs.Smoke);
//	            smoke.target = this;
//	            smoke.DriftAudio = sounds.Brake;

                //Grab reference to Rigidbody
                rb = GetComponent <Rigidbody>();
                //Set angular velocity (This is necessary for fast)
                rb.maxAngularVelocity = 1000f;

                //Set object name

                gameObject.name = nickname;

                //Set character
                if (CharacterId >= 0 && CharacterId < Data.ActiveData.Characters.Length)
                {
                    SetCharacter(Data.ActiveData.Characters[CharacterId]);
                }

                //Create objects and components based on ball type
                if (type == BallType.Player && cameraBall == null && isLocalPlayer)

                {
                    OmniCamera newCam = Instantiate(prefabs.Camera);
                    newCam.Target   = rb;
                    newCam.CtrlType = ctrlType;
                    PivotCamera oldCam = Instantiate(prefabs.OldCamera);
                    oldCam.Target   = rb;
                    oldCam.CtrlType = ctrlType;

                    //Create camera
                    if (Data.ActiveData.GameSettings.useOldControls)
                    {
                        cameraBall = oldCam;
                        newCam.gameObject.SetActive(false);

                        ((PivotCamera)cameraBall).UseMouse = ctrlType == ControlType.Keyboard;
                    }
                    else
                    {
                        cameraBall = newCam;
                        oldCam.gameObject.SetActive(false);
                    }
                    cameraBall.Target   = rb;
                    cameraBall.CtrlType = ctrlType;

                    if (CameraCreatedEvent != null)
                    {
                        CameraCreatedEvent(this, new CameraCreationArgs(cameraBall, oldCam.gameObject, newCam.gameObject));
                    }
                }
                if (type == BallType.LobbyPlayer)
                {
                    //Make the lobby camera follow this ball
                    var cam = FindObjectOfType <LobbyCamera>();
                    if (cam)
                    {
                        cam.AddBall(this);
                    }
                }
                if ((type == BallType.Player || type == BallType.LobbyPlayer) && isLocalPlayer && input == null)
                {
                    //Create input component
                    input = gameObject.AddComponent <BallControlInput>();
                }
                if (type == BallType.AI)
                {
                }
            }
        }
Exemplo n.º 3
0
        private void Update()
        {
            //Input
            var     targetDirectionOffset = Quaternion.identity;
            Vector2 camVector             = GameInput.CameraVector(CtrlType);
            Vector3 orientedCamVector     = new Vector3(camVector.x, 0, camVector.y);

            if (orientedCamVector != Vector3.zero)
            {
                Quaternion camQuaternion = Quaternion.Slerp(Quaternion.identity, Quaternion.LookRotation(orientedCamVector), orientedCamVector.magnitude);
                targetDirectionOffset = camQuaternion;
            }

            if (Target != null)
            {
                //Rotate the camera towards the velocity of the rigidbody

                //Set the up vector, and make it lerp towards the target's up vector if the target has a Ball
                Vector3 targetUp = Vector3.up;
                Ball    bc       = Target.GetComponent <Ball>();
                if (bc)
                {
                    targetUp = bc.Up;
                }
                BallLocal bcLocal = Target.GetComponent <BallLocal>();
                if (bcLocal)
                {
                    targetUp = bcLocal.Up;
                }

                up = Vector3.Lerp(up, targetUp, Time.deltaTime * 10);

                //Based on how fast the target is moving, create a rotation bending towards its velocity.
                Quaternion  towardsVelocity = (Target.velocity != Vector3.zero) ? Quaternion.LookRotation(Target.velocity, up) : Quaternion.identity;
                const float maxTrans        = 20f;
                Quaternion  finalTargetDir  = Quaternion.Slerp(currentDirection, towardsVelocity, Mathf.Max(0, Mathf.Min(-10 + Target.velocity.magnitude, maxTrans) / maxTrans));

                //Lerp towards the final rotation
                currentDirection = Quaternion.Slerp(currentDirection, finalTargetDir, Time.deltaTime * 2);

                //Look for a BallControlInput and set its look direction
                BallControlInput bci = Target.GetComponent <BallControlInput>();
                if (bci != null)
                {
                    bci.LookDirection = currentDirection;
                }



                BallControlInputLocal bciLocal = Target.GetComponent <BallControlInputLocal>();
                if (bciLocal != null)
                {
                    bciLocal.LookDirection = currentDirection;
                }

                //Set camera FOV to get higher with more velocity
                AttachedCamera.fieldOfView = Mathf.Lerp(AttachedCamera.fieldOfView, Mathf.Min(60f + (Target.velocity.magnitude), 100f), Time.deltaTime * 4);

                currentDirectionWithOffset = Quaternion.Slerp(currentDirectionWithOffset, currentDirection * targetDirectionOffset, Time.deltaTime * 2);
                transform.position         = Target.transform.position + Vector3.up * orbitHeight + currentDirectionWithOffset * (Vector3.back * orbitDistance);
                transform.rotation         = currentDirectionWithOffset;
            }
        }