void InitReferences() { spriteRenderer = GetComponent <SpriteRenderer>(); collisionTransform = transform.Find("Collision"); groundedDetector = collisionTransform.GetComponent <CharacterGroundedDetector>(); audioSource = GetComponent <AudioSource>(); }
// Start is called before the first frame update void Start() { characterGroundedDetector = transform.Find("Object").GetComponent <CharacterGroundedDetector>(); switch (type) { case SpringType.Yellow: animator.Play("Yellow Normal"); break; case SpringType.Red: animator.Play("Red Normal"); break; } }
void InitReferences() { characterGroundedDetector = GetComponent <CharacterGroundedDetector>(); topPositionObj = transform.Find("Top Position").gameObject; }
// Keeps character locked to ground while in ground state // 3D-Ready: No, but pretty close, actually. public bool GroundSnap() { RaycastHit hit = GetGroundRaycast(); balanceState = BalanceState.None; if (GetIsGrounded(hit)) { transform.eulerAngles = new Vector3( 0, 0, Quaternion.FromToRotation(Vector3.up, hit.normal).eulerAngles.z ); Vector3 newPos = hit.point + (transform.up * 0.5F * sizeScale); newPos.z = position.z; // Comment this for 3D movement position = newPos; groundedDetectorCurrent = hit.transform.GetComponentInChildren <CharacterGroundedDetector>(); return(true); } // Didn't find the ground from the player center? // We might be on a ledge. Better check to the left and right of // the character to be sure. for (int dir = -1; dir <= 1; dir += 2) { RaycastHit hitLedge; Physics.Raycast( position + (dir * transform.right * 0.375F * sizeScale * sizeScale), // origin -transform.up, // direction out hitLedge, 0.8F * sizeScale, // max distance ~solidRaycastMask // layer mask ); if (GetIsGrounded(hitLedge)) { balanceState = dir < 0 ? BalanceState.Left : BalanceState.Right; groundedDetectorCurrent = hitLedge.transform.GetComponentInChildren <CharacterGroundedDetector>(); Vector3 newPos = ( hitLedge.point - (dir * transform.right * 0.375F * sizeScale) + (transform.up * 0.5F * sizeScale) ); newPos.x = position.x; newPos.z = position.z; position = newPos; return(true); } } if (stateCurrent == "rolling") { stateCurrent = "rollingAir"; } else { stateCurrent = "air"; } return(false); }
void Awake() { groundedDetector = platformColliderObj.GetComponent <CharacterGroundedDetector>(); moveDestinationLocation = transform.Find("Move Destination"); platformTransform = transform.Find("Platform"); }
void Awake() { rigidbody = GetComponent <Rigidbody>(); groundedDetector = GetComponent <CharacterGroundedDetector>(); }