Jump to content
gamecreator

Collisionmesh In Scene Breaks Collision

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

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

Then you build a new one. I can show you how I do my shapes sometime. Shapes without collapsing models for me doesn't produce great results for my purposes.

Share this post


Link to post

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.

Share this post


Link to post
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

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...