Jump to content

Can You Move A Collision Mesh With A Model Without Code?


gamecreator
 Share

Go to solution Solved by Rick,

Recommended Posts

I tried to make a simple gate that lowers when a button is pressed.  The gate itself works perfectly; a single bone moves it up or down.

gate1.png.36508b603e6ac0a995a576ec24317703.png

However, the problem is that I can't tie the collision mesh to it in any way so that it moves with the gate.  I've tried:

1.  Skinning the collision mesh as well with the gate bone (Leadwerks converted it into a non-physics model)
2.  Skinning the collision mesh with its own bone and moving both bones together (same conversion)
3.  Creating a collision mesh in the model editor (did not move with model)

gate2.png.9523acbd72b1744dd19f068ba0060453.png

Must the collision mesh be moved separately by code or is there a way to make this work?

Link to comment
Share on other sites

  • 2 weeks later...

Yes.  The collision box in the last picture doesn't move at all.  I generated it at animation frame 0 but when I animated the model (in the screenshot it is frame 32) the collision box didn't move down.  This makes sense because a model could be complex and anything could be going on, including multiple pieces moving in different directions but I wanted to test to see what would happen.  Ideally you could tie a collisionmesh to a bone but Leadwerks doesn't seem to support that.

I was mostly just looking for some sort of alternative, short of doing it by code.

Link to comment
Share on other sites

  • 3 weeks later...

Do you have a link to the tutorial page?  The ones I found use code to move the doors.  That said, I did think of two "workarounds" since then that I haven't tried yet:

  • Joining the shape and the model as a prefab.  I figure this should work.
  • Using a single line in the code to parent the door and collision shape together.  The point of this thread was to avoid code but it's not the worst to do this during map initialization.
Link to comment
Share on other sites

No sorry I mean the tutorial as you can find one in the examples map Josh made. 

So you want to avoid loading time by initialising the map am I right?

I think in the principle, moving a shaped element and becoming consequences of this has something to do with massed object and that s why joints and no animation will be used. 

It seems to run as if animations are into the domain of "decoration" while shape, collision, mass more like supporting "behind the scene" ground elements. Sorry not sure if I can express this good.

 

 

Link to comment
Share on other sites

1 hour ago, Rick said:

CSG shape as a child in the editor?

Would this work?  How would it know which bone to follow if there's more than one bone?  Or imagine if there was a double door in a single mesh (each with a bone).  Hmm.  I guess a prefab wouldn't work either for this reason.

Link to comment
Share on other sites

On 5/20/2020 at 2:21 AM, Rick said:

CSG shape as a child in the editor?

I think this is worth a try. The invisible shape CSG shape should be parented to each bone, it is a good idea. (you could seperate the mesh and passing them to each bone simply with blender if necessery)

 

 

Link to comment
Share on other sites

Tested and it seems to work!  I created a box (door) with a bone skinned to it and moved it around and exported it as an animated FBX.  Then I created another box (doorcol) with just the collision mesh as another exported FBX.  I then parented doorcol to door in a scene and then saved the whole thing as a prefab.
shot.png.8d8ebbdf9277732f8615fabb8724e18b.png
Then I used the following code to load and animate the prefab:

#include "Leadwerks.h"

using namespace Leadwerks;
Entity* entity = NULL;

int main(int argc, const char *argv[])
{
	Leadwerks::Window* window = Leadwerks::Window::Create();
	Context* context = Context::Create(window);
	World* world = World::Create();

	Camera* camera = Camera::Create();
	camera->Turn(0, 15, 0);
	camera->Move(-1, 1, -4);
	camera->SetDebugPhysicsMode(true);  //  Set camera to see physics shapes

	Light* light = DirectionalLight::Create();
	light->SetRotation(35, 35, 0);

	//  Make a sphere
	Model* sphere = NULL;
	sphere = Model::Sphere();
	sphere->SetColor(1.0, 0.0, 0.0);
	sphere->SetPosition(0, -1, 0);


	Entity *model = Prefab::Load("Prefabs/thedoor.pfb");
//	Entity *model = Model::Load("Models/door/door.mdl");  //  Sanity check


	while(true)
	{
		if(window->Closed() || window->KeyDown(Key::Escape)) return false;

		model->SetAnimationFrame(Leadwerks::Time::GetCurrent() / 30.0, 1, 0);

		Leadwerks::Time::Update();
		world->Update();
		world->Render();
		context->Sync();
	}
	return 0;
}

The result (yes, the animation is sloppy but it was just to test it; and I put the collision off to the side so it's easier to see):
colmovewithbone.gif.586fba8cdc75558a215a0999d26209d0.gif
Thank you everyone for the help.
 

  • Like 2
Link to comment
Share on other sites

I just worked today on this model and I had to think about this thread ^^

Somehow the same problematic happens now to me and I do not see any solution if not seperate the mesh and use a joint ??

Here the animation is turning the propeller (without shape!), but I need the poly mesh as shape so the player can enter in the building...

588608895_Capturedcran(11).thumb.png.ee07ed0172bfb0adbbf4499009d450f9.png

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...