Jump to content

Physics Bug when creating items


Recommended Posts

This is an update to a thread that I've already created on this subject.

 

Previously the cause was expected to be due to collisions in the self physics. I've since changed my model to have a cleaner physics.

 

Video shows two bugs.

 

 

1. Creating items will sometimes have them thrown off in a random direction. (Depends on players position). As seen in the video, when the same action is done in a different position of the map. The object falls as normal.

 

2. There's an unknown physics object stopping me from walking in a section of my map. I have no idea what it is. This one may be hard to produce.

 

Source code will be messaged to Josh after I finish compressing and uploading it.

Link to comment
Share on other sites

I added a collision hook on this entity.

 

Video:

 

Code:

 

this->model = (Model*)Model::Load(item->GetModelPath())->Copy(true);
this->model->SetUserData(this);
this->model->AddHook(Entity::CollisionHook, ItemEntity::CollisionHook);
this->model->SetVelocity(Vec3(0, 0, 0), true);
this->model->SetCollisionType(Collision::Prop);
this->model->SetPhysicsMode(Entity::RigidBodyPhysics);
this->model->SetPickMode(WF_PICK_MODE, true);
this->model->SetMass(10); // TODO: real mass
this->model->SetSweptCollisionMode(true);
this->model->SetPosition(position, true);

 

Collision Hook

void ItemEntity::CollisionHook(Entity* entity0, Entity* entity1, float* position, float* normal, float speed)
{
System::Print("Collision");
System::Print(entity0->GetKeyValue("name"));
System::Print(entity1->GetKeyValue("name"));
printf("Posit(%f, %f, %f)\n", position[0], position[1], position[2]);
printf("Norm(%f, %f, %f)\n", normal[0], normal[1], normal[2]);
printf("Speed: %f\n", speed);
System::Print("EndCollision");
}

 

 

See attached file for console printing.

 

------------------

 

I removed everything from my map and tested a few other objects with different collision types.

 

 

Some things I've learned.

Polymesh doesn't have gravity.

Size matters if it is less than 0.5 feet.

 

Could this be a difference between float and double precision? I've scaled my object up to 5 feet and I still get the same weird collisions.

Collision.txt

Link to comment
Share on other sites

  • 2 weeks later...

I need a file to test.

 

Your model needs a shape, either that gets loaded with it or one you create in code. No shape = no collision.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Please provide instructions on exactly what I need to do to produce behavior that is not correct. I don't know which map to load, what to do, etc. Also please tell me where the script or CPP file is that controls the action in question.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

In ItemEntity.cpp change this line:

this->model = (Model*)Model::Load(path)->Copy(true);

 

To this:

this->model = (Model*)Model::Load(path);

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

What's happening is you're creating two copies of the object and it causes them to shoot away from each other really fast.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

You did uncover another bug. Cone shapes were not being rotated properly when the object was scaled. biggrin.png

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

What's happening is you're creating two copies of the object and it causes them to shoot away from each other really fast.

 

How do they collide if I only set the position of the cloned one? I believe you when this is happening. When I change the code to this, it also works.

Model* base = Model::Load(path);
 base->Hide();
 base->SetPosition(Vec3(-1, -1, -1), true);
 this->model = (Model*)base->Copy(true);
 this->model->Show();
 this->model->SetPosition(position, true);
 this->model->SetVelocity(Vec3(0, 0, 0), true);
 this->model->SetCollisionType(Collision::Prop);
 this->model->SetPhysicsMode(Entity::RigidBodyPhysics);
 this->model->SetPickMode(Entity::PolygonPick, true);
 this->model->SetMass(10); // TODO: real mass
 this->model->SetUserData(this);
 this->model->SetSweptCollisionMode(true);

 

The reason I need the cloned model is so that I can change the material on a single instance of the object to light it on fire.

 

Is there a better way to do this? I'm also doing something similar with trees, rocks, and NPCs as they all have a customized material.

Link to comment
Share on other sites

WHen you load the model with the Asset::Unmanaged flag you can set a material without affecting other instances.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

That is odd. If I use this code it works just fine. So why are they colliding?

 

    ItemEntity::ItemEntity(std::string path, Vec3 position)

{

Model* base = Model::Load(path, Asset::Unmanaged);

this->model = (Model*)base->Copy(true);

base->Release();

this->model->SetPosition(position, true);

this->model->SetVelocity(Vec3(0, 0, 0), true);

this->model->SetCollisionType(Collision::Prop);

this->model->SetPhysicsMode(Entity::RigidBodyPhysics);

this->model->SetPickMode(Entity::PolygonPick, true);

this->model->SetMass(10); // TODO: real mass

this->model->SetUserData(this);

this->model->SetSweptCollisionMode(true);

}

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Okay, I found the cause. Good news, you are also not a crazy person. The specific setup you had would create a giant physics box in the middle of the map. I fixed it.

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...