rigidbody.MovePosition missing collisions

Hi Guys,

I’m trying to calculate my own physics.

        protected override bool Initialise()
        {
            Time.timeScale = 0.1f;
            // start velocity
            deltaVelocity = transform.forward * (muzzleVelocity * 0.80f);
            Debug.Log("Initial velocity: " + deltaVelocity);
            return base.Initialise();
        }

        #region PhysicsTrajectory
        protected override void FixedUpdate()
        {
            base.FixedUpdate();

            if (rigidBody)
                rigidBody.MovePosition(CalculateDeltaTrajectory());
        }

        protected virtual Vector3 CalculateDeltaTrajectory()
        {
            Vector3 deltaPosition = transform.position;

            deltaVelocity.y = deltaVelocity.y - 9.81f * Time.deltaTime;

            return deltaPosition + deltaVelocity * Time.deltaTime;
        }

I have a gameObject with has a sphere collider and a rigidbody. Sphere collider is all set to defaults and is unchanged from me adding it. The rigidbody, all the variables are set the default, apart from the collision detection, which is set to ‘Continous’.

I’m using rididbody.MovePosition, which is supposed to recognise physics collisions. It recognises ‘some’ of the collisions, however others (certain terrain angles), it doesn’t pick up. I’ve manually done AddForce and the objects have followed the same trajectory and made collisions. So I know it’s not it’s trajectory path itself, it’s it’s collisions upon moving.

Does anyone know of a problem with my script? Asides it being super basic right now :P.

Any help if possible. I really want to know what’s causing the objects to travel through terrain ‘sometimes’, and hit other times, while I’m using rigidbody.MovePosition().

Thanks!

MovePosition is not constrained by collisions. If you are seeing what appears to be constraining, it is ptobably the interpenetration solver fixing things. Unless you wish to do your own collision test sweeps you are surely easier off modifying velocity rather than position.

Yeah I get what you mean Thermal. I was thinking that may be the case. In the end I’ve gone for this: http://wiki.unity3d.com/index.php?title=DontGoThroughThings.

The reason being I think the drag function Unity uses is the standard drag equation: Force Drag = 1/2 mass density * flow velocity relative to object * Drag Coefficient * Area. I don’t know how they’ve tallied up flow velocity (air pressure) in their case. I don’t know whether they’re considering mass density as well. They are asking you to add a mass, but I’m not sure whether they’re putting a calculation of that vs the area of mass and the cross sectional density of the object relative to it’s trajectory. I would be able to make an algorithm to measure mass density and things myself, but I don’t know HOW the physics in Unity is being calculated :(. Plus this constant drag model only works on subsonic speeds.

Anyways, that issue’s semi-sorted now, thanks!

MovePosition is definitely constrained by collisions.

The usual reason for penetration is thin colliders. Reducing the fixed timestep will generally solve it.

1 Like

I see, I will have to go investigate and get my facts straight.

Thanks James :slight_smile: I’ll have a look at that. Though the DontGoThroughThings has also worked a treat