void Awake() { typ = Grundtype.normal; mainCam = GameObject.FindGameObjectWithTag("MainCamera").transform; rigid = GetComponent <Rigidbody>(); rigid.interpolation = RigidbodyInterpolation.Interpolate; if (GetComponent <Collider>().material.name == "Default (Instance)") { PhysicMaterial pMat = new PhysicMaterial(); pMat.name = "Frictionless"; pMat.frictionCombine = PhysicMaterialCombine.Multiply; pMat.bounceCombine = PhysicMaterialCombine.Multiply; pMat.dynamicFriction = 0f; pMat.staticFriction = 0f; GetComponent <Collider>().material = pMat; } floorCheckers = new Transform[floorChecks.childCount]; for (int i = 0; i < floorCheckers.Length; i++) { floorCheckers[i] = floorChecks.GetChild(i); } }
public bool IsGrounded() { float dist = GetComponent <Collider>().bounds.extents.y; bool done = false; foreach (Transform floorCheck in floorCheckers) { RaycastHit hit; if (Physics.Raycast(floorCheck.position, Vector3.down, out hit, dist + 0.05f)) { IOnPlayerBounce PB = hit.transform.GetComponent <IOnPlayerBounce>(); if (PB != null && done == false) { PB.OnPlayerBounce(); done = true; } if (hit.transform.tag == "Ice") { typ = Grundtype.ice; } else if (hit.transform.tag == "Mud") { typ = Grundtype.mud; } else { typ = Grundtype.normal; } if (!hit.transform.GetComponent <Collider>().isTrigger) { slope = Vector3.Angle(hit.normal, Vector3.up); if (slope > slopeLimit) { Vector3 slide = new Vector3(0f, -slideAmount, 0f); rigid.AddForce(slide, ForceMode.Force); } return(true); } } } return(false); }