private void SetCharacter(Data.CharacterInfo c) { GetComponent <Renderer>().material = c.material; GetComponent <TrailRenderer>().material = c.trail; transform.localScale = new Vector3(c.ballSize, c.ballSize, c.ballSize); if (c.alternativeMesh != null) { GetComponent <MeshFilter>().mesh = c.alternativeMesh; } //set collision mesh too if (c.collisionMesh != null) { if (c.collisionMesh.vertexCount <= 255) { Destroy(GetComponent <Collider>()); MeshCollider mc = gameObject.AddComponent <MeshCollider>(); mc.sharedMesh = c.collisionMesh; mc.convex = true; } else { Debug.LogWarning("Vertex count for " + c.name + "'s collision mesh is bigger than 255!"); } } BallLocal motion = GetComponent <BallLocal>(); if (motion != null) { motion.characterStats = c.stats; } }
public RacePlayerLocal(BallLocal ball) { sr = StageReferences.Active; lap = 1; ball.CanMove = false; ball.CheckpointPassed += Ball_CheckpointPassed; ball.RespawnRequested += Ball_RespawnRequested; ball.SwitchCamerasEvent += Ball_SwitchCameraRequest; currentCheckpointPos = sr.checkpoints[0].transform.position; this.ball = ball; ball.CameraCreated += (sender, e) => { ballCamera = e.CameraCreated2; oldBallCamera = e.OldCamera2; newBallCamera = e.NewCamera2; ballCamera.SetDirection(sr.checkpoints[0].transform.rotation); }; checkpointTimes = new float[StageReferences.Active.checkpoints.Length]; SetNextCheckpoint(); }
public void AddBall(BallLocal b) { ballsLocal.Add(b); }
// Use this for initialization private void Start() { ballControl = GetComponent <BallLocal>(); //PathToFollow pathToFollow = GameObject.FindWithTag("AIPath").GetComponent <Path>(); }
private void Start() { LookDirection = Quaternion.Euler(Vector3.forward); ball = GetComponent <BallLocal>(); }
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; } }