I'm having problem with the function RigidBody.Moveposition , it just doesn't move if the rigidbody is to kinematic , I checked the documentation but didn't find anything there either , am I missing something??
of course I did attach the script to the game object Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using TheCOLDDev.Forces; namespace TheCOLDDev { public class TM_CharacterController : MonoBehaviour { [Header("Reference")] public Rigidbody m_Body; public CapsuleCollider m_Collider; public CapsuleCollider m_CollidsionChecker; [Header("Values")] public Vector3 m_Velocity = Vector3.zero; public float OverlapCheckRadius = 1; public LayerMask OverlapLayer; [Header("Gravity")] public bool m_Grounded; public List<TC_Gravity> m_GravityForces = new List<TC_Gravity>(); public LayerMask GroundMask; public Vector3 m_GravityForcesVelocity = Vector3.zero; public Vector3 m_GravityVelocity; protected Vector3 p_FinalVelocity = Vector3.zero; // Start is called before the first frame update void Start() { } // Update is called once per frame void FixedUpdate() { m_GravityForcesVelocity = Vector3.zero; p_FinalVelocity = Vector3.zero; f_CalculateVelocity(); f_CalculateGravity(); f_MoveCharacter(); Depentrate(); } #region Movement protected virtual void f_CalculateVelocity() { p_FinalVelocity += m_Velocity; } protected virtual void f_MoveCharacter() { m_Body.MovePosition(m_Body.position + p_FinalVelocity * Time.fixedDeltaTime); } protected virtual void f_CalculateGrounded() { RaycastHit hit; m_Grounded = Physics.SphereCast(m_Collider.transform.position + m_Collider.center , m_Collider.radius , m_GravityForcesVelocity , out hit , m_Collider.height / 2 , GroundMask ,QueryTriggerInteraction.UseGlobal); } protected virtual void f_CalculateGravity() { for(int i =0; i < m_GravityForces.Count;i++) { m_GravityForcesVelocity += m_GravityForces[i].GetGravity(m_Body.position); } f_CalculateGrounded(); m_GravityVelocity += m_GravityForcesVelocity * Time.fixedDeltaTime; if(m_Grounded) m_GravityVelocity = Vector3.zero; m_Velocity += m_GravityVelocity; } #endregion #region Depentration public virtual void Depentrate() { Collider[] p_Colliders = new Collider[4]; Vector3 DepentrationVector = Vector3.zero; int i_ = Physics.OverlapSphereNonAlloc(transform.position , OverlapCheckRadius , p_Colliders ,OverlapLayer , QueryTriggerInteraction.UseGlobal); for( int i =0; i < i_;i++) { Vector3 DepentrationDirection = Vector3.zero; float DepentrationDistance = 0; Physics.ComputePenetration(m_Collider , transform.position + m_Collider.center , transform.rotation, p_Colliders[i] , p_Colliders[i].transform.position , p_Colliders[i].transform.rotation,out DepentrationDirection , out DepentrationDistance); DepentrationVector += DepentrationDirection*DepentrationDistance; // Debug.Log(i_); // Debug.Log(p_Colliders[i].gameObject); } m_Body.MovePosition(m_Body.position + DepentrationVector); } #endregion } } Ignore the gravity part it just returns a vector3 in required direction. even if it was buggy I tried same thing thing without it and setting the isKinematic to true in the inspector and the rigidbody stopped moving suddenly , I don't know what's causing this at all
Start slapping Debug.Logs in there to see what it's doing, make sure that p_FinalVelocity actually has the value you think it has.
yes it has that velocity it moves fine when not kinematic but as soon as I make it kinematic it just stop,I'm really getting frustrated over this, I mean MovePosition are mainly for kinematic bodies then what the heck is wrong with this???
I found out something interesting , I'm able to call MovePosition only once per fixed update from my script,is this officially documented somewhere???