I'm having a lot of problems with setting up a kinematic character controller because of inaccurate capsuleCasts. The problem I'm having is that when the the capsule(Player) is far from wall it detects it (Though I'm not sure it gets the accurate points either) but when the capsule is touching the wall after it have moved, the capsule cast doesn't register the object for some reason,It isn't overlapping or something as far as I checked my code ,I'm hoping someone tell what am i missing or is there a problem with unity physics itself and there is an workaround This is my code : Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class TMT_CapsulePlacer : MonoBehaviour { public Transform Head; public Transform Bottom; public CapsuleCollider m_Collider; public Vector3 Direction = Vector3.forward; public KeyCode ActivationKey = KeyCode.W; public Rigidbody m_Body; // Start is called before the first frame update void Start() { } // Update is called once per frame private void Update() { if(Input.GetKeyDown(ActivationKey)) { RaycastHit hit; if(Physics.CapsuleCast(Head.position , Bottom.position , m_Collider.radius , Direction , out hit, Direction.magnitude)) { transform.position += Direction.normalized * hit.distance; Debug.Log("Hit position = " + hit.point); }else { transform.position += Direction; Debug.Log("No Obstacle Detected"); } } } } (I just made this smaller version to find what exactly was the problem) and here is my scene setup: I hope someone is able to help me
I tried to use boxCast and had problems with it, so I presumed it's buggy and stopped using it. there's another problem mentioned with these just today
if you want to work that with high velocity then you have to change collison detection on rigidbody from discrete to one of continuous, depands which one suits your needs
Hi there, still having problem with CheckBox do you mind posting a simple example of a working script with CheckBox, let's say just a cube detecting plane underneath it no moving nothing special just a call this to damn CheckBox method that works as expected.
For anyone interested the workaround I found was: -Instead of casting a ray from the origin, I set the origin some 'extraCast' amount in the opposite side of sweep direction and then increase the raycast distance by 'extraCast' amount as well. -Then decrease the hit.distance by 'extraCast' to get the actual distance and point