I want to prevent UnityEngine.RigidBody from slipping through.

Asked 2 years ago, Updated 2 years ago, 428 views

I'm having trouble trying to script an object on Unity, but I'm having trouble getting it through.

I want to create objects that move automatically in the +X direction and behave like objects that are affected by gravity and obstacles.

They slip through the obstacles they have installed and move to the other side.

  • Many sites cited "change collision detection algorithms" as a way to resolve skips, but the problem did not disappear by using either Discrete, Continuous, Continuous Dynamic, or Continuous Specific.
  • If you slow down enough, you won't have any problems. However, since you're thinking about creating a race game, it's hard to accept the solution to slow down to the point where this problem doesn't occur from the point of view of game fun.

Unity Screen

Object Car Components Movement Programs:

using UnityEngine;

RequireComponent (type of (Rigidbody))]
public class movement —MonoBehavior
{
    SerializeField Range (-20f, 20f) float speed = 10f;
    Rigidbody rigid;
    void Start() {
        rigid=GetComponent<Rigidbody>();
    }
    voidFixedUpdate(){
        Vector3 velocity = new Vector3 (speed, 0, 0);
        rigid.MovePosition(rigid.position+velocity*Time.fixedDeltaTime);
    }
}

unity3d debugging game-development

2022-09-30 22:03

1 Answers

Rigidbody.MovePosition() has been investigated in the past and its behavior is tricky, so I have never actually used it.It moves differently depending on the value of IsKinematic.Why don't you give it a try?

In addition, physical engines are not responsible for determining the hit of objects moving at high speeds.For example, Ray is fired from the source to the destination coordinate, and if Ray does not collide, it moves to that coordinate.

This is used in FPS bullets (click to attack).This method is also used in the official Unity sample FPS.Most of the FPS in the world should be made like this.

In games, you can't just make it because you want to make something like this.There are many examples such as adding Mesh Collider to the shape of everything you can see, or specifying the range of attacks in collider or XXcast instead of hitting a weapon.

To learn these things, I think it's better to download a sample project and find out how it works.


2022-09-30 22:03

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.