1 registered members (TipmyPip),
18,618
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Few questions about PhysX
#368919
04/29/11 14:16
04/29/11 14:16
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
OK, so as I realized, in "physics" forum, no one was able to answer me. That the main reason for that I've decided to ask my questions here. I'm trying to make simple 2D movement, with BOX hull shape for player. I need to move character only in X coordinates, all other coordinated should be locked. I need physic object to be able to turn only in TILT, all other angles should be locked. I want character to react for all forces and gravity as well, not only movement forces by keys. Here you can download demo of what I've tried to do: Download linkAnd you can see it here (for those lazy ones):
///////////////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
#include <ackphysX.h>
///////////////////////////////////////////////////////////////////////////////
STRING* test_wmb = "test.WMB";
///////////////////////////////////////////////////////////////////////////////
action object()
{
pXent_settype(my,PH_RIGID,PH_BOX); // dynamic box
pXent_setskinwidth(my,0);
pXent_setccdskeleton(my,vector(0,0,0),1);
}
///////////////////////////////////////////////////////////////////////////////
function set_camera()
{
vec_set(camera.x,vector(my.x,my.y - 700,my.z));
camera.pan = 90;
camera.tilt = 0;
}
///////////////////////////////////////////////////////////////////////////////
action hero()
{
VECTOR temp;
player = my;
pXent_settype(my,PH_CHAR,PH_BOX); // box character
wait(1); // wait one frame as manual says
pXent_setskinwidth(my,0);
pXent_setccdskeleton(my,vector(0,0,0),1);
while(1)
{
temp.x = 10 * (key_d - key_a) * time_step;
temp.y = 10 * (key_w - key_s) * time_step;
temp.z = 10 * (key_q - key_e) * time_step;
pXent_moveglobal(my,temp,nullvector);
//pXent_movechar(my,temp,nullvector,0);
set_camera();
wait(1);
}
}
///////////////////////////////////////////////////////////////////////////////
function main()
{
fps_max = 60;
physX_open(); // load physX
level_load(test_wmb); // load level
wait(3); // wait for 3 frames
pX_setccd(1); // activate CCD
// make nice 2D physics
pXent_setbodyflagall(NX_BF_FROZEN_POS_Y|NX_BF_FROZEN_PAN|NX_BF_FROZEN_ROLL,1);
pX_setgravity(vector(0,0,-9.81)); // apply earth gravity
}
///////////////////////////////////////////////////////////////////////////////
So, my questions are: * how to lock all physic objects in Y, Z, PAN, ROLL (pXent_setbodyflagall doesn't help)? * how to make PH_CHAR object to react on other forces (for example, gravity and explosions)? * how to make character collide with other RIGID bodies properly (so they don't pass throw each other, CCD doesn't help)?
|
|
|
Re: Few questions about PhysX
[Re: 3run]
#369328
05/03/11 16:13
05/03/11 16:13
|
Joined: Feb 2010
Posts: 886
Random
User
|
User
Joined: Feb 2010
Posts: 886
|
For simulating an explosion, you could change the entity from a character controller to a physics object - maybe a ragdoll - and afterwards back to a character controller. Yes, but to do that, you have to delete the ragdoll and create the player new at the same place. If you let the player turn into a ragdoll, and then start the player function again with the same model, you will become a unmoveable, wired on the groung laying charector, whith you can`t really conrtoll...
Last edited by Random; 05/03/11 16:18.
|
|
|
Re: Few questions about PhysX
[Re: Random]
#369727
05/06/11 15:01
05/06/11 15:01
|
Joined: Jul 2000
Posts: 28,024 Frankfurt
jcl

Chief Engineer
|

Chief Engineer
Joined: Jul 2000
Posts: 28,024
Frankfurt
|
Random: No, permanently deleting or creating ragdolls is certainly not such a good idea. Better create your ragdolls and character controller already at game start, and switch player model control between them dependent on the situation. At least that's what the grown-up game programmers are supposed to do in commercial games. 3run: In all our levels collision works fine with character controllers. It's very simple, so I'm not sure why you have problems. Look here for a short script that demonstrates all 4 movement modes: http://manual.3dgamestudio.net/pXent_move.htmIt uses a new function, pXent_move, which you don't have, but in version 8.20 you can just call pXent_moveglobal instead. pXent_move will replace pXent_moveglobal/local in next week's new public beta. Movement with gravity is covered in the walking script example in the manual. For detecting the ground per USE_BOX, better use a flat disk collision shape rather than an ellipsoid.
|
|
|
Re: Few questions about PhysX
[Re: jcl]
#369734
05/06/11 16:37
05/06/11 16:37
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
Something strange happened, I can't move character via "pXent_moveglobal" anymore. I just downloaded demo, I posted in first post, and it doesn't work... Player changes it's position to the "nullvector" and doesn't move. It moves if I do it like this: "dist.x += 10 * (key_w - key_s) * time_step;" But if I do it like this, character passes throw level blocks (but collides with Ridig bodies). Same happens if I use the example script you've posted link to. I can move character normally with "pXent_movechar", but I'm getting problem with collisions again: Example one: Example two: Here is example I tried to get working:
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
#include <ackphysX.h>
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
action box_obj()
{
pXent_settype(my,PH_RIGID,PH_BOX);
}
action ball_obj()
{
pXent_settype(my,PH_RIGID,PH_SPHERE);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
var my_height;
VECTOR dist;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
action hero()
{
pXent_settype(my,PH_CHAR,PH_BOX);
wait(-1);
while(1)
{
DEBUG_VAR(my_height,30);
my_height = c_trace(my.x,vector(my.x,my.y,my.z-500), IGNORE_ME|USE_BOX);
if(my_height > 5){dist.z -= 1 * time_step;}else{dist.z = 0;}
dist.x = 10 * (key_d - key_a) * time_step;
dist.y = 0;
//pXent_moveglobal(my,dist,nullvector);
pXent_movechar(my,dist,nullvector,0);
vec_set(camera.x,vector(my.x,my.y - 700,my.z));
wait(1);
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
function main()
{
fps_max = 60;
physX_open();
level_load("test.WMB");
wait(3);
vec_set(camera.pan,vector(90,0,0));
pXent_setbodyflagall(NX_BF_FROZEN_POS_Y|NX_BF_FROZEN_PAN|NX_BF_FROZEN_ROLL,1);
pX_setgravity(vector(0,0,-9.81));
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
One more problem I found with making gravity for character, take a look at the screen: At this position, gravity starts applying, cause trace returns far distance to ground. But cause characters hull is BOX like, it doen't move down. Example is in script above. Could you please check example I posted above, may be reason for all bugs I get with collusions is bad scripting? Could you please give me an idea for workaround problem with gravity? Or may be in next update you'll make BOX shape for trace? How do I change to "flat disk" shape for trace? I've never heard about it.
|
|
|
|