Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Rigid Body.MovePosition() not detecting collisions

Discussion in 'Physics' started by alexmmusic, Jul 9, 2023.

  1. alexmmusic

    alexmmusic

    Joined:
    Sep 25, 2020
    Posts:
    10
    Hi!

    I'm trying to make a character controller for a 3rd person game, it just have to move in all directions and move with the camera rotation.

    It's all working fine but the collisions. I can't detect collisions and I think the parameters are all correct (even the collision detection is set to continous).

    At low speed the collisions work, but it should work at any speed.

    Here is the movement code:

    Code (CSharp):
    1. void moveCharacter(Vector3 direction)
    2.     {
    3.         // Convert direction into Rigidbody space.
    4.         direction = rb.rotation * direction;
    5.        
    6.         rb.MovePosition(rb.position + direction * speed * Time.fixedDeltaTime);
    7.      
    8.          
    9.     }
    and this the FixedUpdate:

    Code (CSharp):
    1.  private void FixedUpdate()
    2.     {
    3. xAxis = Input.GetAxis("Horizontal");
    4.         yAxis = Input.GetAxis("Vertical");
    5.   inputsKeys = new Vector3(xAxis, 0, yAxis);
    6.      
    7.         inputNormalized = inputsTeclas.normalized;
    8.  
    9.         if (Input.GetMouseButton(1))
    10.         {
    11.             Cursor.visible = false;
    12.          
    13.         else
    14.         {
    15.             Cursor.visible = true;
    16.         }
    17.  
    18.      
    19.  
    20.  
    21.         moveCharacter(inputsNormalized);
    22.     }
    Thanks for all
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
    Use velocity instead. Moveposition just changed the position, so if you skip over a collider, it doesn't register it.
     
  3. alexmmusic

    alexmmusic

    Joined:
    Sep 25, 2020
    Posts:
    10
    I tried but I don't know how to apply the rotation to the rigidbody
     
  4. KillDashNine

    KillDashNine

    Joined:
    Apr 19, 2020
    Posts:
    449
    angularVelocity