Jump to content

Collisionmesh In Scene Breaks Collision


 Share

Recommended Posts

I have the following scene with a ground and a ball (together in one fbx/mdl but four separate models: ground, ground collision shape, sphere, sphere collision shape) and a code-generated character controller.

scene.thumb.jpg.28a74472a33e8471e319de766d3686b7.jpg

The ground and the ball have their own collision shapes.  If they're both collisionhull, everything is fine.  However, if either one is a collisionmesh, the controller falls through the ground, even though the camera physics debug (and the model editor) shows that the collision meshes are there.

Below is the code and attached is the Models folder with all of the fbx and mdl files.

#include "Leadwerks.h"

using namespace Leadwerks;

Entity* player = 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->SetRotation(25, 0, 0);
	camera->Move(0, 0, -16);
	camera->SetDebugPhysicsMode(true);

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

	Model* scene = Model::Load("Models/scene_bothcollisionhull.mdl");  //  This works!
//	Model* scene = Model::Load("Models/scene_bothcollisionmesh.mdl");  //  This doesn't work - controller falls through ground
//	Model* scene = Model::Load("Models/scene_groundcollisionmesh_spherecollisionhull.mdl");  //  This doesn't work - controller falls through ground
//	Model* scene = Model::Load("Models/scene_groundcollisionhull_spherecollisionmesh.mdl");  //  This doesn't work - controller falls through ground

	//  The next 3 lines don't seem to be necessary but I tried them anyway
//	scene->SetMass(0);
//	scene->SetPhysicsMode(Entity::RigidBodyPhysics);
//	scene->SetCollisionType(Collision::Scene);

	//Create a character
	player = Pivot::Create();
	Entity* visiblecapsule = Model::Cylinder(16, player);
	visiblecapsule->SetScale(1, 2, 1);
	visiblecapsule->SetPosition(0, 1, 0);
	player->SetMass(1);
	player->SetPhysicsMode(Entity::CharacterPhysics);
	player->SetPosition(0, 1, 0);

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

		Leadwerks::Time::Update();

		float move = (window->KeyDown(Key::Up) - window->KeyDown(Key::Down)) * 4;
		float strafe = (window->KeyDown(Key::Right) - window->KeyDown(Key::Left)) * 4;
		player->SetInput(0, move, strafe);

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

Comment out one of the Model::Load lines and uncomment another one to load a different combination.

Models.zip

Link to comment
Share on other sites

Don't have time to look at this right now but it's worth asking if you yourself created the collision or these are editor generated shapes. Are the models collapsed? I have issues with non-collapsed models myself.

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

I should have been more clear that they're four individual models I created in 3DS Max.  By collapsing do you mean combining into one?  I could certainly combine the ground and the sphere but the idea is to have two separate collision types in one scene and that can't be done with one model (you need at least one named collisionhull and at least one named collisionmesh).

Since I use physics debug, I think I could have simplified this by not even having visible models, just the collision meshes.

Link to comment
Share on other sites

1 hour ago, gamecreator said:

I'm curious about your process and what collapsing models improves.  Maybe you could either blog or post elsewhere about it.  In the meantime, I think the collisionmesh bug remains.

Yeah, I think I will. Keep an eye out for it

  • Like 1

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

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...