void Start() { controller = GetComponent <CharacterController>(); //get the transform of a child with a camera component cam = transform.GetComponentInChildren <Camera>()?.transform; if (cam == null) { print("Getting cinemachina camera"); cam = transform.GetComponentInChildren <CinemachineVirtualCamera>().transform; } standingHeight = controller.height; cameraOffset = standingHeight - cam.localPosition.y; //Handle custom input names if (customInputNames) { jumpBtn = jumpBtnCustom; crouchBtn = crouchBtnCustom; runBtn = runBtnCustom; unlockMouseBtn = unlockMouseBtnCustom; xInName = xInNameCustom; yInName = yInNameCustom; xMouseName = xMouseNameCustom; yMouseName = yMouseNameCustom; } controllerInfo = GetInfo(); ExecuteExtension("Start"); }
public override void ExPreMove(ref TFPData data, TFPInfo info) { Vector3 dir = data.currentMove * Time.deltaTime; Vector3 checkPos = transform.position + dir; if (Physics.Raycast(checkPos + Vector3.up, Vector3.down, out hit)) { string tag = hit.collider.tag; Vector3 step = -dir.normalized * collisionResolution; Vector3 nonTaggedPos = transform.position; if (Unwalkable.Contains(tag)) { for (int a = -90; a < 90; a += collisionStepAngle) { checkPos = (Quaternion.Euler(0, a, 0) * dir) + transform.position; Physics.Raycast(checkPos + Vector3.up, Vector3.down, out hit); tag = hit.collider.tag; if (!Unwalkable.Contains(tag)) { nonTaggedPos = checkPos; if (a > 0) { break; } } } data.currentMove = nonTaggedPos - transform.position; data.currentMove *= 1 / Time.deltaTime; } } }
public override void ExPostUpdate(ref TFPData data, TFPInfo info) { if (data.timeSinceGrounded <= Time.deltaTime && data.jumping) { src.PlayOneShot(sound); } }
AudioClip GetClip(TFPInfo info) { if (Physics.SphereCast(transform.position + (Vector3.up * info.controller.radius), info.controller.radius, Vector3.down, out groundTypeCheck, info.crouchHeadHitLayerMask.value)) { TerrainCollider hitTerrain = groundTypeCheck.transform.GetComponent <TerrainCollider>(); MeshRenderer hitMesh = groundTypeCheck.transform.GetComponent <MeshRenderer>(); Texture2D hitTexture; // if(hitTerrain != null){ // hitTexture = TerrainSurface.GetMainTexture(groundTypeCheck.transform.GetComponent<Terrain>(), transform.position); // }else if(hitMesh != null){ // hitTexture = hitMesh.material.mainTexture as Texture2D; // }else{ return(defaultFootsteps.footSounds[Random.Range(0, defaultFootsteps.footSounds.Length)]); // } print(hitTexture); foreach (FootstepGroup fsGroup in footsteps) { foreach (Texture2D tex in fsGroup.textures) { if (hitTexture == tex) { return(fsGroup.footSounds[Random.Range(0, fsGroup.footSounds.Length)]); } } } } return(defaultFootsteps.footSounds[Random.Range(0, defaultFootsteps.footSounds.Length)]); }
public override void ExPreUpdate(ref TFPData data, TFPInfo info) { if (disablePlayerLook && forceLook) { data.mouseLookEnabled = false; } else { data.mouseLookEnabled = true; } }
public override void ExPreMove(ref TFPData data, TFPInfo info) { if ((!data.grounded || data.slide) && !data.jumping) { if (data.jumpPressed > 0) { jetting = true; data.timeSinceGrounded = info.coyoteTime + Time.deltaTime; data.jumpPressed = 0; } if (data.jumpHeld && fuelLeft > 0) { jetting = true; data.yVel = jetPower; if (limitFuel) { fuelLeft -= Time.deltaTime; if (fuelLeft < 0) { fuelLeft = 0; } } jetSound.volume = Mathf.MoveTowards(jetSound.volume, 1.0f, soundFadeSpeed * Time.deltaTime); } else { jetting = false; } } else if (data.grounded) { jetting = false; fuelLeft = Mathf.MoveTowards(fuelLeft, fuel, fuelRegain * Time.deltaTime); } else { jetting = false; } if (!jetting) { jetSound.volume = Mathf.MoveTowards(jetSound.volume, 0.0f, soundFadeSpeed * Time.deltaTime); } if (fuelLeft < fuel) { fuelGuage.text = "FUEL: " + fuelLeft.ToString("F2") + " / " + fuel; } else { fuelGuage.text = ""; } }
public override void ExPreMove(ref TFPData data, TFPInfo info) { data.currentMove += floatingPlatform; floatingPlatform = Vector3.zero; if (beenPushed) { data.yVel += pushDirection.y; data.currentMove += new Vector3(pushDirection.x, 0f, pushDirection.z); timeSincePushed = Time.time; pushDirection = Vector3.zero; control = 0f; beenPushed = false; } }
public override void ExPreUpdate(ref TFPData data, TFPInfo info) { if (control == 0f && Time.time > timeSincePushed + 0.3f && data.grounded) { control = 1f; data.moving = true; print("Regain control"); } else if (control == 0f) { data.moving = false; } data.xIn = Mathf.Lerp(data.xIn, 0f, freezePercentage); data.yIn = Mathf.Lerp(data.yIn, 0f, freezePercentage); }
public override void ExPreMove(ref TFPData data, TFPInfo info) { if (forceLook) { GetLastLook(data, info); if (isAngle) { lookAngle = lookValue; } else { lookAngle = Quaternion.LookRotation(lookValue - info.cam.position).eulerAngles; } float newHorLook = Mathf.MoveTowardsAngle(lastHorLook, lookAngle.y, lookSpeed * Time.deltaTime); float newVerLook = Mathf.MoveTowardsAngle(lastVerLook, lookAngle.x, lookSpeed * Time.deltaTime); Vector3 newLook = new Vector3(newVerLook, newHorLook, 0.0f); transform.eulerAngles = new Vector3(0.0f, newLook.y, 0.0f); info.cam.localEulerAngles = new Vector3(newLook.x, 0.0f, 0.0f); } }
public override void ExPostUpdate(ref TFPData data, TFPInfo info) { if (data.moving && data.grounded) { float deltaMove = Vector3.Scale(data.lastMove, new Vector3(1, 0, 1)).magnitude *Time.deltaTime; leftDistance -= deltaMove; rightDistance -= deltaMove; if (leftDistance <= 0) { leftDistance += distanceBetweenFootsteps * 2; leftFoot.PlayOneShot(GetClip(info)); } if (rightDistance <= 0) { rightDistance += distanceBetweenFootsteps * 2; rightFoot.PlayOneShot(GetClip(info)); } } else { leftDistance = 0; rightDistance = distanceBetweenFootsteps; } }
//executes during the FixedUpdate function in FPSController.cs. Use for physics interactions public virtual void ExFixedUpdate(ref TFPData data, TFPInfo info) { }
public override void ExPostMove(ref TFPData data, TFPInfo info) { currentVelocity = data.moveDelta / Time.deltaTime; grounded = data.grounded; }
/* * executes before the controller.Move function is called in FPSController.cs * YVel is applied to current move after this * This means that YVel represents the vertical movement * and currentmove represents the horizontal movement * * use this if you want to add custom movement functionality */ public virtual void ExPreMove(ref TFPData data, TFPInfo info) { }
public override void ExStart(ref TFPData data, TFPInfo info) { fuelLeft = fuel; }
//executes at the end of the Update function in FPSController.cs public virtual void ExPostUpdate(ref TFPData data, TFPInfo info) { }
public override void ExStart(ref TFPData data, TFPInfo info) { leftDistance = 0; rightDistance = distanceBetweenFootsteps; }
public override void ExPostMove(ref TFPData data, TFPInfo info) { UpdateLine(); }
public override void ExStart(ref TFPData data, TFPInfo info) { pos = new Vector3[] { transform.position }; }
void GetLastLook(TFPData data, TFPInfo info) { lastHorLook = transform.eulerAngles.y; lastVerLook = info.cam.localEulerAngles.x; lastLook = new Vector3(lastVerLook, lastHorLook, 0.0f); }
//executes at the end of the Start function in FPSController.cs public virtual void ExStart(ref TFPData data, TFPInfo info) { }