InitialCollisionDetected event not firing

Discuss any questions about BEPUphysics or problems encountered.
Troubled3rdYear
Posts: 9
Joined: Mon Apr 29, 2013 9:48 am

InitialCollisionDetected event not firing

Post by Troubled3rdYear »

The function assigned to the InitialCollisionDetected event for my (Prefab) Sphere, does not fire when it collides with a StaticMesh. Oddly enough though, the StaticMesh's event function does.
Is there a solution to this?


Also, I seem to have an issue where calling following can result in the Sphere's speed apparently continuously increasing, while position remains the same and it not accepting any further impulses.

Code: Select all

        void Stabalise(float dt)
        {
            Vector3 v = -Rigidbody.LinearVelocity;
            if (v.Length() > 0.1)
            {
                if (v.Length() > (dt * Speed))
                {
                    v.Normalize();
                    v *= (dt * Speed);
                }
                Rigidbody.ApplyLinearImpulse(ref v);
                ForceApplied = true;
            }
        }
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: InitialCollisionDetected event not firing

Post by Norbo »

The function assigned to the InitialCollisionDetected event for my (Prefab) Sphere, does not fire when it collides with a StaticMesh. Oddly enough though, the StaticMesh's event function does.
Is there a solution to this?
Could you reproduce the issue in the latest version of the BEPUphysicsDemos so I can take a look?
Also, I seem to have an issue where calling following can result in the Sphere's speed apparently continuously increasing, while position remains the same and it not accepting any further impulses.
I'm not entirely clear on the context, but I can see two potential issues:

1) The intent of the linear impulse appears to be changing the velocity directly. Applying a linear impulse is not equivalent to applying a change to linear velocity unless the object's mass is 1.
2) It looks like the intent of the code is to limit the maximum speed of the entity. However, it is not doing that; right now, it's just applying a backwards impulse with magnitude equivalent to the maximum speed. If the intent is to limit the speed, then the velocity beyond the maximum speed should be subtracted.
Troubled3rdYear
Posts: 9
Joined: Mon Apr 29, 2013 9:48 am

Re: InitialCollisionDetected event not firing

Post by Troubled3rdYear »

Norbo wrote:Could you reproduce the issue in the latest version of the BEPUphysicsDemos so I can take a look?
It seems to be working fine in that version, is there and updated dll & xml somewhere? (1.2.0 is the version I have been using)

Norbo wrote:I'm not entirely clear on the context
The aim of the function is braking, it has nothing to do with capping the top speed.
The issue is that calling that function seems to cause the Sphere to cease behaving correctly.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: InitialCollisionDetected event not firing

Post by Norbo »

It seems to be working fine in that version, is there and updated dll & xml somewhere? (1.2.0 is the version I have been using)
Nope, I've been procrastinating on a proper full release; v1.3.0's dll/xml just have to be compiled from source for now. (I plan to rectify this in the next couple of months as I wrap up another subproject; the current setup is fairly inconvenient for non-XNA users.)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: InitialCollisionDetected event not firing

Post by Norbo »

I have a guess at what the problem with the sphere is: it went to sleep. ApplyLinearImpulse is an extremely direct-access method which, for performance reasons, does not try to wake the entity up. Sleeping objects do not update, so the position won't change regardless of the velocity.

You can either force it awake by setting entity.ActivityInformation.Activate() or by using the LinearMomentum/LinearVelocity convenience properties which force the entity awake for you.
Troubled3rdYear
Posts: 9
Joined: Mon Apr 29, 2013 9:48 am

Re: InitialCollisionDetected event not firing

Post by Troubled3rdYear »

You can either force it awake by setting entity.ActivityInformation.Activate()
Worked perfectly thank you. Though is there away to force it always be awake?


In regards to using the compiled dll/xml files from the latest build, pardon my ignorance but how do I set my project to use them. (I'm not too familiar with either VS nor XNA (Use to using Codeblocks and OpenGL))
Simply C&Ping them causes errors, presumable due to the additional dll which I'm not sure how to add to the project.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: InitialCollisionDetected event not firing

Post by Norbo »

Worked perfectly thank you. Though is there away to force it always be awake?
entity.ActivityInformation.IsAlwaysActive = true will do the trick.
In regards to using the compiled dll/xml files from the latest build, pardon my ignorance but how do I set my project to use them. (I'm not too familiar with either VS nor XNA (Use to using Codeblocks and OpenGL))
Simply C&Ping them causes errors, presumable due to the additional dll which I'm not sure how to add to the project.
Right clicking the references in the visual studio project and adding BEPUphysics.dll and BEPUutilities.dll should be sufficient. By default, both the added .dlls will be copied to the output directory on build, ensuring everything will work. For the .xml files, just make sure they're adjacent to the .dlls so that they can be found for intellisense purposes.
Troubled3rdYear
Posts: 9
Joined: Mon Apr 29, 2013 9:48 am

Re: InitialCollisionDetected event not firing

Post by Troubled3rdYear »

Adding the dll's resulted in the following compiler errors;

Code: Select all

Error	1	The type or namespace name 'Collidables' does not exist in the namespace 'BEPUphysics' (are you missing an assembly reference?)	L:\Users\Cameron\Desktop\ICT309\Drain Explorer\CODE\BasicSetupDemo\BasicSetupDemo\PowerUp.cs	12	19	BasicSetupDemo
Error	2	The type or namespace name 'Collidables' does not exist in the namespace 'BEPUphysics' (are you missing an assembly reference?)	L:\Users\Cameron\Desktop\ICT309\Drain Explorer\CODE\BasicSetupDemo\BasicSetupDemo\PowerUp.cs	13	19	BasicSetupDemo
Error	3	The type or namespace name 'Collidables' does not exist in the namespace 'BEPUphysics' (are you missing an assembly reference?)	L:\Users\Cameron\Desktop\ICT309\Drain Explorer\CODE\BasicSetupDemo\BasicSetupDemo\InGameState.cs	14	19	BasicSetupDemo
Error	4	The type or namespace name 'Collidables' does not exist in the namespace 'BEPUphysics' (are you missing an assembly reference?)	L:\Users\Cameron\Desktop\ICT309\Drain Explorer\CODE\BasicSetupDemo\BasicSetupDemo\InGameState.cs	15	19	BasicSetupDemo
Error	5	The type or namespace name 'MathExtensions' does not exist in the namespace 'BEPUphysics' (are you missing an assembly reference?)	L:\Users\Cameron\Desktop\ICT309\Drain Explorer\CODE\BasicSetupDemo\BasicSetupDemo\InGameState.cs	16	19	BasicSetupDemo
Error	6	The type or namespace name 'EntityCollidable' could not be found (are you missing a using directive or an assembly reference?)	L:\Users\Cameron\Desktop\ICT309\Drain Explorer\CODE\BasicSetupDemo\BasicSetupDemo\PowerUp.cs	37	34	BasicSetupDemo
Error	7	The type or namespace name 'Collidable' could not be found (are you missing a using directive or an assembly reference?)	L:\Users\Cameron\Desktop\ICT309\Drain Explorer\CODE\BasicSetupDemo\BasicSetupDemo\PowerUp.cs	37	59	BasicSetupDemo
Error	8	The type or namespace name 'Collidables' does not exist in the namespace 'BEPUphysics' (are you missing an assembly reference?)	L:\Users\Cameron\Desktop\ICT309\Drain Explorer\CODE\BasicSetupDemo\BasicSetupDemo\PlayerDrone.cs	12	19	BasicSetupDemo
Error	9	The type or namespace name 'Collidables' does not exist in the namespace 'BEPUphysics' (are you missing an assembly reference?)	L:\Users\Cameron\Desktop\ICT309\Drain Explorer\CODE\BasicSetupDemo\BasicSetupDemo\PlayerDrone.cs	13	19	BasicSetupDemo
Error	10	No overload for 'HandleImpact' matches delegate 'BEPUphysics.BroadPhaseEntries.Events.InitialCollisionDetectedEventHandler<BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable>'	L:\Users\Cameron\Desktop\ICT309\Drain Explorer\CODE\BasicSetupDemo\BasicSetupDemo\PlayerDrone.cs	59	79	BasicSetupDemo
Error	11	The type or namespace name 'EntityCollidable' could not be found (are you missing a using directive or an assembly reference?)	L:\Users\Cameron\Desktop\ICT309\Drain Explorer\CODE\BasicSetupDemo\BasicSetupDemo\PlayerDrone.cs	240	34	BasicSetupDemo
Error	12	The type or namespace name 'Collidable' could not be found (are you missing a using directive or an assembly reference?)	L:\Users\Cameron\Desktop\ICT309\Drain Explorer\CODE\BasicSetupDemo\BasicSetupDemo\PlayerDrone.cs	240	59	BasicSetupDemo
Error	13	The type or namespace name 'EntityCollidable' could not be found (are you missing a using directive or an assembly reference?)	L:\Users\Cameron\Desktop\ICT309\Drain Explorer\CODE\BasicSetupDemo\BasicSetupDemo\PlayerDrone.cs	242	51	BasicSetupDemo
Were these namespaces renamed or am I at fault?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: InitialCollisionDetected event not firing

Post by Norbo »

The content of Collidables was indeed merged into the BroadPhaseEntries namespace.
Troubled3rdYear
Posts: 9
Joined: Mon Apr 29, 2013 9:48 am

Re: InitialCollisionDetected event not firing

Post by Troubled3rdYear »

Ok, I got it compiling

In regards to my initial problem, it seems the issue was my code not BEPU. Sorry for wasting your time without thoroughly checking through my code first.

As you can see from the collision function below, it will not do anything if it collides with a static collider anyway:

Code: Select all

public void HandleImpact(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
        {
            var otherEntityInformation = other as EntityCollidable;
            if (otherEntityInformation != null)
            {
                Vector3 rv = otherEntityInformation.Entity.LinearVelocity - Rigidbody.LinearVelocity;
                float x = rv.Length() - 2.5f;  // MINUS minimum relative vel that can cause dmg
                if (x > 0)
                {
                    HealthMod(-x);
                    SoundCrashHeavy.Play(0.25f, 0.0f, 0.0f);
                }
                else
                    SoundCrash.Play(0.25f, 0.0f, 0.0f);  // volume, pitch, blah
            }
        }
Updated working function:

Code: Select all

public void HandleImpact(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
        {
            Vector3 rv = Rigidbody.LinearVelocity;

            var oei = other as EntityCollidable;
            if (oei != null)
                rv -= oei.Entity.LinearVelocity;

            float x = rv.Length() - 2.5f;  // MINUS minimum relative vel that can cause dmg
            if (x > 0)
            {
                HealthMod(-x);
                SoundCrashHeavy.Play(0.25f, 0.0f, 0.0f);
            }
            else
                SoundCrash.Play(0.25f, 0.0f, 0.0f);  // volume, pitch, blah
        }
Troubled3rdYear
Posts: 9
Joined: Mon Apr 29, 2013 9:48 am

Re: Attaching Entity to parent

Post by Troubled3rdYear »

Sorry for the double post, I have another question.

What kind of constraint would I use if I want something to be 'held' (remain fixed distance from. when parent rotates, it rotates around parent. (essentially Become a transformational child)) by another entity?
I thought WeldJoint was meant for this, but it results in the child 'hanging down' as if by rope to the parent.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: InitialCollisionDetected event not firing

Post by Norbo »

WeldJoint is the correct constraint. It's actually just a combination of a BallSocketJoint and an NoRotationJoint; if relative rotation between the connected entities seems to be allowed, then the NoRotationJoint got disabled somehow. Usually this would be done by setting the WeldJoint.NoRotationJoint.IsActive = false.
Troubled3rdYear
Posts: 9
Joined: Mon Apr 29, 2013 9:48 am

Re: InitialCollisionDetected event not firing

Post by Troubled3rdYear »

Yeah, that did it. Along with a high MaxCorrectiveVelocity, applying parents forces to child and disabling the childs gravity;
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: InitialCollisionDetected event not firing

Post by Norbo »

Hmm, I'm not sure I fully understand the situation, so I'll just say a few things for clarity:
1) WeldJoint.NoRotationJoint.IsActive defaults to true, and that is how it should stay in order for the angular portion to function. Setting it to false stops the NoRotationJoint from doing anything.
2) The default MaxCorrectiveVelocity is float.MaxValue; changing it should not be necessary unless you want to slow down the joint's corrective speed.
3) Applying parent forces to the child and disabling child gravity should not be necessary if the WeldJoint is functioning properly. All forces applied to one connected entity will be propagated physically through the weld to the other connected entity.
Troubled3rdYear
Posts: 9
Joined: Mon Apr 29, 2013 9:48 am

Re: InitialCollisionDetected event not firing

Post by Troubled3rdYear »

Here is my current relevant code, which does not result in the desired behavior. Specifically it seems the attached object (B) does not rotate about the owner's (A) origin.
Is there something wrong with the way I'm doing things?

Code: Select all

public void AttemptToGrab()
        {
            if (Grabber == null)
            {
                Ray myRay = new Ray(Rigidbody.Position + Rigidbody.WorldTransform.Forward * (SphereRadius + 0.5f), Rigidbody.WorldTransform.Forward);
                RayCastResult result;
                //float length = 1.0f;
                if (Space.RayCast(myRay, out result)) // myRay, length, out result
                {
                    Console.WriteLine("Ray Hit " + (Rigidbody.Position - result.HitData.Location).Length());

                    var o = result.HitObject as EntityCollidable;
                    if (o != null)// && o.Entity.IsDynamic)
                    {
                        //Vector3 v = Rigidbody.WorldTransform.Forward;
                        //o.Entity.ApplyLinearImpulse(ref v);

                        o.Entity.IsAffectedByGravity = false;
                        Grabber = new WeldJoint(Rigidbody, o.Entity); //weld
                        //Grabber.NoRotationJoint.IsActive = true;
                        //Grabber.BallSocketJoint.IsActive = true;
                        //Grabber.BallSocketJoint.MaxCorrectiveVelocity = 10;
                        Space.Add(Grabber);

                        Console.WriteLine("Grabbed");
                    }
                    else
                        Console.WriteLine("Cant grab this");
                }
                else
                    Console.WriteLine("Ray Miss");
            }
        }
Post Reply