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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Is transformation of Rgdbody Directly Proportional to How Easy it Gets to Penetrate a Box Collider ?

Discussion in 'Scripting' started by gsammbunny, Oct 2, 2018.

  1. gsammbunny

    gsammbunny

    Joined:
    Mar 7, 2016
    Posts:
    66
    Scenario: I got a rigid-body (0) between two box colliders like this,
    | 0 |


    Problem:
    The RigidBody between those Box Colliders whose position transforms on x-axis with a swipe penetrates when transformation gets fast. I don't want it to get out of those box colliders at all

    Code is Attached Below:
    Code (CSharp):
    1. using TouchControlsKit;
    2. using UnityEngine;
    3.  
    4. public class move : MonoBehaviour
    5. {
    6.     public Rigidbody rb;
    7.     public Vector3 teleportPoint;
    8.  
    9.     private void Start()
    10.     {
    11.         rb = GetComponent<Rigidbody>();
    12. }
    13.     private void Update()
    14.     {
    15.         //transform.position = new Vector3((transform.position.x + TCKInput.GetAxis("Touchpad").x * 2), transform.position.y, transform.position.z);
    16.         teleportPoint = new Vector3((transform.position.x + TCKInput.GetAxis("Touchpad").x * 3), transform.position.y, transform.position.z);
    17.         rb.MovePosition(teleportPoint);
    18.     }
    19. }
    20.  
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    First of all, you should consider using FixedUpdate for the modification of the rigidbody. FixedUpdate is called during the physics-update of the engine, kinda like Update being the major per-frame update function.

    Next thing to check is pobably the thickness of your colliders, do not configure them to be extremely thin.
    In order to improve collision detection, you can also change the collision detection mode of the involved rigidbodies. Note that this may impact performance, as computation may take more time, as described in the documentation for the CollisionDetectionMode.
     
    Last edited: Oct 2, 2018
    gsammbunny likes this.
  3. gsammbunny

    gsammbunny

    Joined:
    Mar 7, 2016
    Posts:
    66
    Thank you I'll try it