About Store Forum Documentation Contact



Post Reply 
[solved]flat ground made of many actors not so flat
Author Message
dziablo Offline
Member

Post: #1
[solved]flat ground made of many actors not so flat
Hi, when im moving ball actor on flat ground made of box actors ball often jump on edge of box actor.

Here edited code from tutorial Physics/actors to check what i mean.
(my edits in bold text)
Quote:/******************************************************************************/
Actor ground, ground2, ground3, ground4,
ground5, ground6, ground7, ground8,

box ,
ball ;
/******************************************************************************/
void InitPre()
{
EE_INIT();
App.flag=APP_MS_EXCLUSIVE;
}
bool Init()
{
Cam.dist=4;

// create physics
Physics.create(EE_PHYSX_DLL_PATH); // create physics by specifying the path to physx dll's

// create actors
ground.create(Box (5, 1, 5, Vec(0.0, -2, 0)), 0); // create ground actor from Box and density=0 (which means it's a static actor - will not move)
ground2.create(Box (5, 1, 5, Vec(0.0, -2, 5)), 0);
ground3.create(Box (5, 1, 5, Vec(0.0, -2, 10)), 0);
ground4.create(Box (5, 1, 5, Vec(0.0, -2, 15)), 0);
ground5.create(Box (5, 1, 5, Vec(5.0, -2, 0)), 0); // create ground actor from Box and density=0 (which means it's a static actor - will not move)
ground6.create(Box (5, 1, 5, Vec(5.0, -2, 5)), 0);
ground7.create(Box (5, 1, 5, Vec(5.0, -2, 10)), 0);
ground8.create(Box (5, 1, 5, Vec(5.0, -2, 15)), 0);

box .create(Box (0.3 , Vec(0.1, 1, 0)));
ball .create(Ball(0.3 , Vec(2.5, 0, 2.5)), 10);

return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
bool Update()
{

if(Kb.bp(KB_ESC))return false;
CamHandle(0.1, 10, CAMH_ZOOM|CAMH_ROT);
// physics update
{
Physics.startSimulation(); // start frame simulation

// physics simulation takes some time, so you can do some calculations here
// important : you may not modify actors between Physics.startSimulation() and Physics.stopSimulation()

Physics.stopSimulation(); // get results of frame simulation
}


flt s=30;

// add forces to ball
if(Kb.b(KB_UP ))ball.addForce(Vec( 0, 0, 1)*s);
if(Kb.b(KB_DOWN ))ball.addForce(Vec( 0, 0, -1)*s);
if(Kb.b(KB_LEFT ))ball.addForce(Vec(-1, 0, 0)*s);
if(Kb.b(KB_RIGHT))ball.addForce(Vec( 1, 0, 0)*s);

// add forces to ball according to camera
if(Kb.b(KB_W))ball.addForce( !PointOnPlane(Cam.matrix.z, Vec(0, 1, 0))*s);
if(Kb.b(KB_S))ball.addForce(-!PointOnPlane(Cam.matrix.z, Vec(0, 1, 0))*s);
if(Kb.b(KB_A))ball.addForce(-!PointOnPlane(Cam.matrix.x, Vec(0, 1, 0))*s);
if(Kb.b(KB_D))ball.addForce( !PointOnPlane(Cam.matrix.x, Vec(0, 1, 0))*s);

// add velocity to ball
if(Kb.bp(KB_SPACE))ball.addVel(Vec(0, 3, 0));
return true;
}
/******************************************************************************/
void Draw()
{
D .clear();
Physics.draw (); // draw physical actors
}
/******************************************************************************/

Just move on the ground and You will see. any ideas how to fix that?
(This post was last modified: 08-07-2013 01:02 PM by dziablo.)
07-29-2013 12:31 PM
Find all posts by this user Quote this message in a reply
kasinova Offline
Member

Post: #2
RE: flat ground made of many actors not so flat
Hey! I'm sure it has something to do with the density of your ball.
08-01-2013 10:07 AM
Find all posts by this user Quote this message in a reply
dziablo Offline
Member

Post: #3
RE: flat ground made of many actors not so flat
Thanks for answer but what do You mean? I changed density from 10(i dont know why it was 10 pfft) to 1 and its all the same.
08-01-2013 12:49 PM
Find all posts by this user Quote this message in a reply
kasinova Offline
Member

Post: #4
RE: flat ground made of many actors not so flat
sorry! the ball actor mass. if it is a heavier mass (which takes more force to move) the less likely it will bounce when colliding with the corners of the ground box
08-02-2013 06:11 AM
Find all posts by this user Quote this message in a reply
SamNainocard Offline
Member

Post: #5
RE: flat ground made of many actors not so flat
The reason of ball being 10 density because of
ball .create(Ball(0.3 , Vec(2.5, 0, 2.5)), 10);

About jumpy, it could be due to being different actor.
08-02-2013 06:24 AM
Find all posts by this user Quote this message in a reply
dziablo Offline
Member

Post: #6
RE: flat ground made of many actors not so flat
Thank You all but what i need is perfectly flat ground.
08-05-2013 06:28 PM
Find all posts by this user Quote this message in a reply
kasinova Offline
Member

Post: #7
RE: flat ground made of many actors not so flat
I built your version of the physics tutorial (I'm still on 1.0) and it works fine. the ball runs smoothly across all ground actors. The only difference in my code from yours is the Physics.create function "../installation/PhysX"

Might not be much help but maybe there is a difference in our physics
08-06-2013 08:46 PM
Find all posts by this user Quote this message in a reply
dziablo Offline
Member

Post: #8
RE: flat ground made of many actors not so flat
When i was looking for that engine stuff in Physics i found this:
Code:
PhysicsClass& skin     (  Flt              skin   );   Flt                skin           ()C {return _skin        ;} // set/get physics skin width (allowed object interpenetration), default=0.005 (changing this value will not affect actors that are already created, in order to have one global skin value, please call this function after physics creation and before any actor creation)
i dont fully understand it but setting skin to 0 solves the problem smile

Thank You everyone for help! Its very nice community i hope ill get good enough some day to help others.

@kasinova Now i believe ball wasnt jumpy when You tested because example code was quite bad. Check that if You want:
Code:
/******************************************************************************/
Actor ground[100],
box,
ball ;
/******************************************************************************/
void InitPre()
{
EE_INIT();
App.flag=APP_MS_EXCLUSIVE;
}
bool Init()
{
Cam.dist=4;

// create physics
Physics.create(EE_PHYSX_DLL_PATH); // create physics by specifying the path to physx dll's
//Physics.skin(0);
// create actors
for(int i=0; i<100; i++)
ground[i].create(Box (5, 1, 5, Vec(i*5, -2, 0)), 0); // create ground actor from Box and density=0 (which means it's a static actor - will not move)

box .create(Box (0.3 , Vec(0.1, 1, 0)));
ball .create(Ball(0.3 , Vec(2.5, 0, 2.5)), 10);

return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
bool Update()
{

if(Kb.bp(KB_ESC))return false;

CamHandle(0.1, 10, CAMH_ZOOM|CAMH_ROT);
// physics update
{
Physics.startSimulation(); // start frame simulation

// physics simulation takes some time, so you can do some calculations here
// important : you may not modify actors between Physics.startSimulation() and Physics.stopSimulation()

Physics.stopSimulation(); // get results of frame simulation
}


flt s=30;

// add forces to ball
if(Kb.b(KB_UP ))ball.addForce(Vec( 0, 0, 1)*s);
if(Kb.b(KB_DOWN ))ball.addForce(Vec( 0, 0, -1)*s);
if(Kb.b(KB_LEFT ))ball.addForce(Vec(-1, 0, 0)*s);
if(Kb.b(KB_RIGHT))ball.addForce(Vec( 1, 0, 0)*s);

// add forces to ball according to camera
if(Kb.b(KB_W))ball.addForce( !PointOnPlane(Cam.matrix.z, Vec(0, 1, 0))*s);
if(Kb.b(KB_S))ball.addForce(-!PointOnPlane(Cam.matrix.z, Vec(0, 1, 0))*s);
if(Kb.b(KB_A))ball.addForce(-!PointOnPlane(Cam.matrix.x, Vec(0, 1, 0))*s);
if(Kb.b(KB_D))ball.addForce( !PointOnPlane(Cam.matrix.x, Vec(0, 1, 0))*s);

// add velocity to ball
if(Kb.bp(KB_SPACE))ball.addVel(Vec(0, 3, 0));
Cam.at = ball.pos();
return true;
}
/******************************************************************************/
void Draw()
{
D .clear();
Physics.draw (); // draw physical actors
D.text(0, 0.6, S+"Engine = "+ Physics.engine()    ); // Physics.engine() is 1;
}
/******************************************************************************/
08-07-2013 01:01 PM
Find all posts by this user Quote this message in a reply
Post Reply