private void CheckGrounded(out float level) { RaycastHit[] hits; Vector3 position; level = Position.y; grounded = false; groundNormal = Vector3.up; groundNormalAngle = 0.0f; position = Position; position.y = Radius; /* * if (Physics.SphereCast(position, Radius - settings.groundSphereShave, Vector3.down, out RaycastHit hit, Radius * Radius, Mask)) * { * level = position.y - hit.distance; * * ground.Procces(); * grounded = !ground.Active; * if (grounded) * { * groundNormal = hit.normal; * } * } */ for (int i = settings.groundCheckResolution; i >= (Velocity.y > 0 ? 0 : -settings.groundCheckResolution); i--) { position = Position; level = (float)(i) / settings.groundCheckResolution * Radius; position.y += level + Radius; hits = Physics.SphereCastAll(position, Radius - settings.groundSphereShave, Vector3.down, settings.groundSphereShave, Mask); if (hits.Length > 0) { level = position.y - Radius - settings.groundSphereShave; ground.Procces(); grounded = !ground.Active; groundNormal = Vector3.zero; foreach (RaycastHit h in hits) { groundNormal += h.normal; } groundNormal /= hits.Length; groundNormal.Normalize(); groundNormalAngle = Vector3.Angle(groundNormal, Vector3.up); return; } } ground.Act(); }
public void Move(float x, float y) { Transform t; Vector3 m; float a; if (!Body.Grounded || (Mathf.Abs(x) < movementSettings.inputDeadzone && Mathf.Abs(y) < movementSettings.inputDeadzone)) { return; } t = Shooter || movementSettings.moveType == MovementSettings.MovementType.Tank ? transform : Camera.transform; if (movementSettings.moveType == MovementSettings.MovementType.Tank) { transform.Rotate(0.0f, x * movementSettings.rotate, 0.0f); x = 0; } m = t.TransformDirection(x, 0, y); m.y = 0; if (m.magnitude > 1) { m.Normalize(); } move.x = m.x; move.y = m.z; moving.Act(); if (!Shooter) { a = Vector3.Angle(transform.forward, m); if (Vector3.Angle(transform.right, m) > 90.0f) { a *= -1; } transform.Rotate(0.0f, a, 0.0f); } }
public void Sprint() { sprinting.Act(); }
public void Crouch() { crouching.Act(); }