void FixedUpdate() { //** Ground Check **// grdInfo = GroundCheck(); //** Rotation to normal **// float normalAdjustSpeed = (grdInfo.rayType == RayType.ForwardRay) ? forwardNormalAdjustSpeed : groundNormalAdjustSpeed; Vector3 slerpNormal = Vector3.Slerp(transform.up, grdInfo.groundNormal, 0.02f * normalAdjustSpeed); Quaternion goalrotation = getLookRotation(Vector3.ProjectOnPlane(transform.right, slerpNormal), slerpNormal); // Save last Normal for access lastNormal = transform.up; //Apply the rotation to the spider if (Quaternion.Angle(transform.rotation, goalrotation) > Mathf.Epsilon) { transform.rotation = goalrotation; } // Dont apply gravity if close enough to ground if (grdInfo.distanceToGround > getGravityOffDistance()) { rb.AddForce(-grdInfo.groundNormal * gravityMultiplier * 0.0981f * getScale()); //Important using the groundnormal and not the lerping normal here! } }
public void Move(Vector3 move) { //normalize the move vector if (move.magnitude > 1.0f) { move = Vector3.Normalize(move); } //Debug.Log ("updated move vector: " + move); //on screen debug //moveText.text = "Move: x = "+move.x+" y = "+move.y+" z = "+move.z; //convert world relative input move vector to local relative move = transform.InverseTransformDirection(move); //check for player ground condition groundInfo currentGround = playerGrounded(); isGrounded = currentGround.onGround; distToGround = currentGround.distance; groundNormal = currentGround.normal; landingPoint = currentGround.landing; //ragdoll death if fall distance is large if (distToGround > maxFallDistance) { ragDoll = true; } //determine local relative player movement if ground conditions are okay move = Vector3.ProjectOnPlane(move, groundNormal); forward = move.z; turn = Mathf.Atan2(move.x, move.z); //update mecanim AC parameters //move allows for updating the AC using polar coordinates animSpeed = Vector3.SqrMagnitude(move); //transition between walk (0.0) and run (1.0)-magnitude not used to improve runtime animDirection = turn; //radians to rotate: +ve - turn right; -ve - turn left updateAC(animSpeed, animDirection, landingPoint); /*on screen debug for what is passed to mecanim * speedText.text = "Speed: " + forward; * directionText.text = "Direction: " + turn; * groundedText.text = "Grounded: " + isGrounded; * distanceText.text = "Distance to Ground: " + distToGround;*/ }
public void Start() { groundInfoComponent = GetComponent <groundInfo>(); gInfo = groundInfoComponent.ground; Owner = groundInfoComponent.owner; }