Jump to content

More Physics Fun


gamecreator
 Share

Recommended Posts

Any idea what causes this?

Ball hits floor which has cubes jointed to it and everything goes crazy.

 

#include "App.h"

using namespace Leadwerks;

App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}

App::~App() { delete world; delete window; }

Model *ballmodel, *levelmodel;
Shape *shape;

Vec3 camerarotation;
#if defined (PLATFORM_WINDOWS) || defined (PLATFORM_MACOS)
bool winmode=true;
#else
bool winmode=false;
#endif

float rotx, rotz;

struct columnstruct
{
Model *model;
Joint *joint;
} column[100];

int columnindex=0;

Joint *joint;

void createcolumn(int i, float x, float y)
{
column[i].model=Model::Load("Models/column.mdl");
Shape *shape=Shape::Load("Models/column.phy");
column[i].model->SetShape(shape);
shape->Release();
column[i].model->SetPosition(x,0,y);
column[i].model->SetPhysicsMode(Entity::RigidBodyPhysics);
column[i].model->SetCollisionType(1);
column[i].model->SetMass(1000);

column[i].joint = Joint::Hinge(x,0,y, 1,0,0, column[i].model, levelmodel);
column[i].joint->SetLimits(0,0);	
column[i].joint->EnableLimits();
}

bool App::Start()
{
window = Window::Create("TiltIt",0,0,1280,720,Window::FullScreen);
context = Context::Create(window);
world = World::Create();

camera = Camera::Create();
camera->Move(0,7,0);
camera->SetRotation(90,0,0);

window->HideMouse();

levelmodel=Model::Load("Models/levelbase.mdl");
Shape* shape;
shape=Shape::Load("Models/levelbase.phy");
levelmodel->SetShape(shape);
shape->Release();
levelmodel->SetPhysicsMode(Entity::RigidBodyPhysics);
levelmodel->SetMass(1000);
levelmodel->SetCollisionType(1);

ballmodel=Model::Load("Models/ball.mdl");
shape=Shape::Load("Models/ball.phy");
ballmodel->SetShape(shape);
shape->Release();
ballmodel->SetPosition(0,2,-1);
ballmodel->SetPhysicsMode(Entity::RigidBodyPhysics);
ballmodel->SetCollisionType(1);
ballmodel->SetMass(1);

createcolumn(columnindex++,3,3);
createcolumn(columnindex++,2,3);
createcolumn(columnindex++,1,3);
createcolumn(columnindex++,0,3);
createcolumn(columnindex++,-1,3);
createcolumn(columnindex++,-2,3);
createcolumn(columnindex++,-3,3);

createcolumn(columnindex++,3,1);
createcolumn(columnindex++,2,1);
createcolumn(columnindex++,1,1);
createcolumn(columnindex++,0,1);
createcolumn(columnindex++,-1,1);
createcolumn(columnindex++,-2,1);
createcolumn(columnindex++,-3,1);

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

rotx=rotz=0;

return true;
}

bool App::Loop()
{
if(window->Closed() || window->KeyHit(Key::Escape)) return false;

levelmodel->PhysicsSetPosition(0,0,0,1.0f);

if(window->KeyDown(Key::Left) || window->TouchDown(0) && !window->TouchDown(1)) rotz+=0.3*Time::GetSpeed();
if(window->KeyDown(Key::Right) || window->TouchDown(0) && window->TouchDown(1)) rotz-=0.3*Time::GetSpeed();
if(window->KeyDown(Key::Up)) rotx+=0.3*Time::GetSpeed();
if(window->KeyDown(Key::Down)) rotx-=0.3*Time::GetSpeed();
levelmodel->PhysicsSetRotation(rotx,0,rotz,0.001f);

Time::Update();
world->Update();
world->Render();

context->Sync(false);

return true;
}

Link to comment
Share on other sites

I am a noob but should the collision type be 1 on levelmodel? I would think it should be set to scene so it applies physics to other objects and does not get affected. Using numbers would scene be 2? Also, does it need a mass of 1000, my scene objects have 0 mass?

 

Just a guess smile.png First thing that came to mind. I tried to test run the code but it was just a black screen for me.

Link to comment
Share on other sites

Good thoughts and sorry, it requires some MDL files and textures - I just wanted to show the code and video.

 

The collision type may be wrong but the goal is to have a level which can rotate but not move. But its rotation should affect a ball moving on top of it (and other things). I'm trying to attach pillars/collumns to a flat level (as you see in the video for a second) but something's going wrong.

 

The mass needs to be high so that a ball doesn't effect it in any way (doesn't make it rotate at the edge, for example).

Link to comment
Share on other sites

Good thoughts and sorry, it requires some MDL files and textures - I just wanted to show the code and video.

 

The collision type may be wrong but the goal is to have a level which can rotate but not move. But its rotation should affect a ball moving on top of it (and other things). I'm trying to attach pillars/collumns to a flat level (as you see in the video for a second) but something's going wrong.

 

The mass needs to be high so that a ball doesn't effect it in any way (doesn't make it rotate at the edge, for example).

 

why don't you rotate camera and ball instead?

Learn to obey

before you command

 

when you see very good tactic

sit back and think again.

 

Basics prince Zuko.

Basics are your greatest strength.

Link to comment
Share on other sites

Also I just done some tests in Unity, saw that if to "map" components is rigidbody attached the children will react to each other.

 

BUT if map has only parent with component with rigidbody than children won't react to each other BUT entire map will react to outer physics.

 

Also if you don't need map to be aplied from outer physics why do you have map as physics reaction?

Make map static colliders and just rotate the parent Entity.

 

and forces of ball or whatever will not interact with map but will apply it's forces on it's self only.

 

so if ball and map get's in contact ball will move BUT map won't.

 

I'm only guessing there's a possibility to do this - my sig says it all, ...

Learn to obey

before you command

 

when you see very good tactic

sit back and think again.

 

Basics prince Zuko.

Basics are your greatest strength.

Link to comment
Share on other sites

I'm trying to make a game where you can rotate the world to have a ball roll from start point to finish point through and around obstacles. The world and columns and obstacles need to rotate to affect the ball and other things properly. You don't control the ball directly. Here's an imagine to give you an idea.

 

screenshot.jpg

 

I was trying to dynamically set up walls and such but it's way more difficult than I thought it would be.

Link to comment
Share on other sites

I'm trying to make a game where you can rotate the world to have a ball roll from start point to finish point through and around obstacles. The world and columns and obstacles need to rotate to affect the ball and other things properly. You don't control the ball directly.

 

OK I do get it so Look my second post, ... as first one is totally out of scope.

 

Ok first thing what other things.

 

1. Start SLOWLY!!!!! After each number test your code!!!

 

2. make static map and ball - ball must not affect map position. !!!!

3. make column on map as child of map - columns must not affect map position !!!!

4. throw ball in to column - column must not move but ball must react !!!!

5. rotate the map. grant parent - everything must rotate correctly !!!

 

6. if all steps went well you have skeleton you wanted.

 

IF not don't go further !!!!! solve what you still can't solve.

and most importantly now you have a mini project to deal with code stripped down in to a just a fraction and it's easy to deal with.

Learn to obey

before you command

 

when you see very good tactic

sit back and think again.

 

Basics prince Zuko.

Basics are your greatest strength.

Link to comment
Share on other sites

I appreciate the tips and it makes sense. It's as if a few boxes work ok but a handful glitch it up - like the joints don't play well with eachother. Will experiment more at home. Also, even just a line of 5 boxes starts slighty shifting up and down (making a slight but visible curve) but I could accept that if that's all it was.

Link to comment
Share on other sites

I appreciate the tips and it makes sense. It's as if a few boxes work ok but a handful glitch it up - like the joints don't play well with eachother. Will experiment more at home. Also, even just a line of 5 boxes starts slighty shifting up and down (making a slight but visible curve) but I could accept that if that's all it was.

 

Really, joints aren't the way to do this. What's really needed, and Josh has talked about finishing up support for at some point, are Convex Decomposition collision shapes. What this does is take an object that has concave elements (your table top and columns, for example) and creates a collision mesh made out of a number of convex elements.

 

Newton has support for this, and you can see in the headers where Josh already has a framework for it.

 

There are other physics properties I'd like to see exposed so we have even more control over objects (or at least a method to get the physics world and Newton bodies so we can access Newton directly, but this not the proper way to do it as it could interfer with the Newton wrapper).

--"There is no spoon"

Link to comment
Share on other sites

Thanks. I'm coming to understand that Leadwerks just can't do this. And since I can't do it, I might as well reveal the now-abandoned project.

 

It was going to be an Android game where you rotate phone/tablet to rotate the world. But since I couldn't do the convex decomposition, I thought it would be fun to have dynamic parts of the world that you could first manipulate to make a path for the ball to the end. So phase 1 would be using your moves to move walls (some of which can only move up or down or side to side), etc and phase 2 would be guiding your ball by moving your phone and avoiding enemies and such.

 

Thanks for the help anyway.

Link to comment
Share on other sites

@GameCreator

 

how do you make a ragdoll?

 

I guess it's a similar thing and try turning head manually of ragdoll.

 

tho I don't know why you have joints but whatever, ...

Learn to obey

before you command

 

when you see very good tactic

sit back and think again.

 

Basics prince Zuko.

Basics are your greatest strength.

Link to comment
Share on other sites

Thanks YouGroove. I don't use Lua but I understand the concept. I very may make an attempt to use a flat world and see how applying forces to the ball based on tilt input feels.

 

Military, I think the difference with ragdolls is that you only have 2 or so joints max attached to each entity/model. Here I have to attach dozens to the floor to make walls and I guess that's too much for Leadwerks or the physics engine.

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