1 registered members (AndrewAMD),
816
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Ball passes through inclined slope instead of rolling down it
#423090
05/24/13 01:30
05/24/13 01:30
|
tolu619
Unregistered
|
tolu619
Unregistered
|
I am working on a simple, basic, mechanical physics simulator. I created a game where the user inputs the mass of the ball, the coefficient of friction and the angle of inclination (with respect to the horizontal) of the inclined slope which the ball is supposed to roll down. Once the user clicks "start simulation", a level is loaded, the inclined plane is created with the ball at one end, and after 3 seconds, the tilt of the plane is suddenly changed to the angle specified by the user. Unfortunately, as soon as the level is loaded, the ball drops right through the inclined plane. The plane is simply a slab I created in WED by selecting Add>Prefab>Plate(large), resizing it to what I wanted and then building it. Here are the codes within my main() function that create both entities.
ENTITY* InclinedPlane = ent_create("InclinedPlane.wmb", vector(160, 16, -186), InclineThePlane); ENTITY* Ball = ent_create("ball.mdl", vector(InclinedPlane.x + 180, InclinedPlane.y, InclinedPlane.z+31), BallPhysics);
The only code I've included to tell the ball how to move is: action BallPhysics() { pXent_settype (me, PH_RIGID, PH_SPHERE); // set the physics entity type pXent_setfriction (me,CoefficientOfFriction); // set the friction on the ground pXent_setdamping (me,LinearDamping,AngularDamping); // set the damping pXent_setelasticity (me,Elasticity); // set the elasticity pXent_setmass(me, MassOfBall); //set the mass }
If I were to comment out the first line of this action, "pXent_settype (me, PH_RIGID, PH_SPHERE);", then the ball would not move at all. It would just hang in the air on the exact spot it was created. Please what am I doing wrong that makes the ball pass right through the inclined plane?
|
|
|
Re: Ball passes through inclined slope instead of rolling down it
[Re: 3dgs_snake]
#423124
05/24/13 10:47
05/24/13 10:47
|
tolu619
Unregistered
|
tolu619
Unregistered
|
#include <acknex.h> #include <default.c> #include <ackphysx.h>
//GLOBAL VARIABLES var MassOfBall = 0; var AngleOfSlope = 0; var CoefficientOfFriction = 0; var LinearDamping = 10; var AngularDamping = 10; var Elasticity = 50; var ForceInNewtons = 10; var Mass = 1; var Velocity; var Acceleration;
var Start = 0;
function IncreaseMass() { MassOfBall = MassOfBall+1; }
function IncreaseAngle() { AngleOfSlope = AngleOfSlope+1; }
function IncreaseFriction() { CoefficientOfFriction = CoefficientOfFriction+1; }
function DecreaseMass() { MassOfBall = MassOfBall-1; MassOfBall = clamp(MassOfBall, 0, 100); }
function DecreaseAngle() { AngleOfSlope = AngleOfSlope-1; AngleOfSlope = clamp(AngleOfSlope, 0, 360); }
function DecreaseFricion() { CoefficientOfFriction = CoefficientOfFriction-1; CoefficientOfFriction = clamp(CoefficientOfFriction, 0, 100); }
PANEL* homescreen = { bmap = "SimpleInclinedPlaneSplash.jpg"; button(610, 165, "IncreaseButtonDown.png", "IncreaseButton.png", "IncreaseButtonDown.png", IncreaseMass, NULL, NULL); button(610, 185, "DecreaseButtonDown.png", "DecreaseButton.png", "DecreaseButtonDown.png", DecreaseMass, NULL, NULL); button(610, 230, "IncreaseButtonDown.png", "IncreaseButton.png", "IncreaseButtonDown.png", IncreaseAngle, NULL, NULL); button(610, 250, "DecreaseButtonDown.png", "DecreaseButton.png", "DecreaseButtonDown.png", DecreaseAngle, NULL, NULL); button(610, 295, "IncreaseButtonDown.png", "IncreaseButton.png", "IncreaseButtonDown.png", IncreaseFriction, NULL, NULL); button(610, 315, "DecreaseButtonDown.png", "DecreaseButton.png", "DecreaseButtonDown.png", DecreaseFricion, NULL, NULL); button(30, 480, "StartSimulationButtonDown.png", "StartSimulationButton.png", "StartSimulationButtonDown.png", StartSimulation, NULL, NULL); digits(307, 170, 3, "Arial#28b", 1, MassOfBall); digits(322, 235, 3, "Arial#28b", 1, AngleOfSlope); digits(463, 304, 3, "Arial#28b", 1, CoefficientOfFriction); layer = 1; flags = SHOW | OVERLAY; }
function StartSimulation() { //if(Monster != NULL && LevelFile != NULL) //this check didn't work. { homescreen.flags = 0; level_load("HollowCube.wmb"); Start = 1; } }
TEXT* InputedVariables = { pos_x = 10; pos_y = 10; layer = 1; font = "Segoe_Print#20"; string ("Mass of Ball:\nAngle Of Slope:\nCoefficient of Friction:"); }
TEXT* WatchedVariables = { pos_x = 600; pos_y = 10; layer = 1; font = "Segoe_Print#20"; string ("Velocity:\nAcceleration:\nTime:\nDisplacement:"); }
PANEL* Variables = { digits(100, 10, 3, "Segoe_Print#20", 1, MassOfBall); digits(120, 30, 3, "Segoe_Print#20", 1, AngleOfSlope); digits(165, 50, 3, "Segoe_Print#20", 1, CoefficientOfFriction); }
function DisplayVariables() { }
action InclineThePlane() { wait(-3); my.tilt = AngleOfSlope; }
action BallPhysics() { pXent_settype (me, PH_RIGID, PH_SPHERE); // set the physics entity type pXent_setfriction (me,CoefficientOfFriction); // set the friction on the ground pXent_setdamping (me,LinearDamping,AngularDamping); // set the damping pXent_setelasticity (me,Elasticity); // set the elasticity pXent_setmass(me, MassOfBall); //set the mass }
function main() { physX_open(); mouse_mode = 4; while(Start==0) wait(1); ENTITY* InclinedPlane = ent_create("InclinedPlane.wmb", vector(160, 16, -186), InclineThePlane); ENTITY* Ball = ent_create("ball.mdl", vector(InclinedPlane.x + 180, InclinedPlane.y, InclinedPlane.z+31), BallPhysics); InputedVariables.flags = SHOW | SHADOW; Variables.flags = SHOW; WatchedVariables.flags = SHOW; camera.x = Ball.x; // keep the camera 300 quants behind the ball camera.y = Ball.y - 440; // using the same y with the ball camera.z = Ball.z; // and place it at z = 1000 quants camera.pan = camera.pan + 110; //camera.tilt = -60; // make it look downwards }
|
|
|
Re: Ball passes through inclined slope instead of rolling down it
[Re: ]
#423126
05/24/13 10:53
05/24/13 10:53
|
tolu619
Unregistered
|
tolu619
Unregistered
|
@3dgs_snake, thanks, I hadn't realized that they must both be physX actors. I inserted this line "pXent_settype(me, PH_RIGID, PH_BOX);" as the first line of my action InclineThePlane() and now, the ball doesn't pass through the plane anymore. However, it seems the mass of the ball won't allow the plane to slope to an angle anymore, and that was working before. It's like the ball just presses the plane flat to the ground.
|
|
|
Re: Ball passes through inclined slope instead of rolling down it
[Re: ]
#423136
05/24/13 11:38
05/24/13 11:38
|
Joined: Feb 2010
Posts: 320 TANA/Madagascar
3dgs_snake
Senior Member
|
Senior Member
Joined: Feb 2010
Posts: 320
TANA/Madagascar
|
Hi, Only physX actors can interract together. However, it seems the mass of the ball won't allow the plane to slope to an angle anymore Perhaps you are setting the tilt after you have created the physX actor. And Perhaps you are creating a PH_RIGID for the plane? You can only set x/y/z pan/tilt/roll before creating a body, otherwise you neet to call pXent_setposition/pXent_rotate. If you are creating a rigid body then It will be affected by gravity, that's why it is falling with the ball. What you can do is : - Set rotation before creating a body and create a PH_STATIC (It is not recommended to displace or rotate a static actor).
- Create a PH_RIGID , set rotation, disable gravity, and other flags.
- Create a kinematic body.
Bellow is an example
#include <acknex.h>
#include <default.c>
#include <ackphysx.h>
void main()
{
video_mode = 4;
physX_open();
level_load( "" );
camera.x = -150;
// Ground
ENTITY *g = ent_create("CUBE.MDL", nullvector, NULL);
vec_set(g->scale_x, vector(5, 5, 0.1));
pXent_settype(g, PH_STATIC, PH_BOX);
// Static Plane
ENTITY *sp = ent_create("CUBE.MDL", vector(0, 0, 50), NULL);
vec_set(sp->scale_x, vector( 0.1, 2, 0.1 ));
// Set tilt
sp->roll = 20;
pXent_settype(sp, PH_STATIC, PH_BOX);
// Rigid Plane
ENTITY *rp = ent_create("CUBE.MDL", vector(0, -20, 35), NULL);
vec_set(rp->scale_x, vector( 0.1, 2, 0.1 ));
// Set tilt
rp->roll = -20;
pXent_settype(rp, PH_RIGID, PH_BOX);
pXent_setbodyflag(rp, NX_BF_DISABLE_GRAVITY, 1);
pXent_setbodyflag(rp, NX_BF_FROZEN_PAN, 1);
pXent_setbodyflag(rp, NX_BF_FROZEN_TILT, 1);
pXent_setbodyflag(rp, NX_BF_FROZEN_ROLL, 1);
pXent_setbodyflag(rp, NX_BF_FROZEN_POS_X, 1);
pXent_setbodyflag(rp, NX_BF_FROZEN_POS_Y, 1);
pXent_setbodyflag(rp, NX_BF_FROZEN_POS_Z, 1);
// Kinematic Plane
ENTITY *kp = ent_create("CUBE.MDL", vector(0, 0, 20), NULL);
vec_set(kp->scale_x, vector( 0.1, 2, 0.1 ));
// Set tilt
kp->roll = 20;
pXent_settype(kp, PH_RIGID, PH_BOX);
pXent_setbodyflag(kp, NX_BF_KINEMATIC, 1);
// Sphere
ENTITY *s = ent_create("SPHERE.MDL", vector(0, 10, 100), NULL);
vec_set(s->scale_x, vector(0.2, 0.2, 0.2));
pXent_settype(s, PH_RIGID, PH_SPHERE);
}
|
|
|
Re: Ball passes through inclined slope instead of rolling down it
[Re: ]
#431333
10/14/13 09:16
10/14/13 09:16
|
Joined: Oct 2013
Posts: 3
markjosol
Guest
|
Guest
Joined: Oct 2013
Posts: 3
|
180, InclinedPlane.y, InclinedPlane.z+31), BallPhysics); ________________________________________________ Fifa Ultimate Team Coins
|
|
|
|