How push object?

Posted By: IDontLikeSoccer

How push object? - 09/12/12 06:03

I have the ball in the level, and I'm interested how can I do when my player touch the ball, the ball start moving with physics.
For ball i use pXent_settype(my, PH_RIGID, PH_SPHERE) and what I need to use for my player because I not need physics for the player, only the possibility that a player can push objects?
Posted By: 3dgs_snake

Re: How push object? - 09/12/12 06:24

Hi,

You can use a character controller, a kinematic actor or an normal entity an apply the force yourself
Posted By: IDontLikeSoccer

Re: How push object? - 09/12/12 07:24

How I can apply force myself? Can you give me some example please?
Posted By: MasterQ32

Re: How push object? - 09/12/12 08:53

you can use pXent_addvelcentral or pXent_addforcecentral
the first one does not depend on the object mass which should be better for your
both functions take the registered entity and a global force/velocity vector
Posted By: IDontLikeSoccer

Re: How push object? - 09/12/12 10:03

Thank you MasterQ32
Posted By: 3dgs_snake

Re: How push object? - 09/12/12 11:12

A simple example for you.

Code:
#include <acknex.h>
#include <default.c>
#include <ackphysX.h>
#include <camera.c>

var ent_collided = FALSE;
ENTITY *colliding_entity = NULL;

// Push ents
void push_ents()
{
   if (event_type == EVENT_ENTITY)  
   {
      ent_collided = TRUE;
      colliding_entity = you;
   }
}


// App entry point
void main()
{
   video_mode = 4;
   fps_max = 60;
   
   // Load empty level
   level_load("");
   
   // Place camera
   vec_set(camera.x, vector(-500, 0, 100));
   camera->tilt = -9;
   
   // Open physX
   physX_open();
   
   ENTITY *ground = ent_createterrain(NULL, nullvector, 128, 128, 10);
   bmap_fill(ent_getskin(ground, 1), vector(0x43, 0x21, 0), 100);
   
   // Create sphere
   ENTITY *ball = ent_create("SPHERE.MDL", vector(100, 0, 20), NULL);
   
   // Create player
   player = ent_create("CUBE.MDL", vector(0, 0, 20), NULL);
   vec_set(player->scale_x, vector(1, 1, 2));
   player.emask |= ENABLE_ENTITY;
   player.event = push_ents;
   
   // Init physX
   pXent_settype(ground, PH_STATIC, PH_POLY);
   pXent_settype(ball, PH_RIGID, PH_SPHERE);
   
   // Set camera mode
   tcamera_mode = 2;   // TPCamera
   tcamera_dist = 50;
   
   // Movement vectors
   VECTOR vMove, vForce, vSpeed;
   vec_set(vMove, nullvector);
   vec_set(vForce, nullvector);
   vec_set(vSpeed, nullvector);
   
   while(1)
   {
      vForce.x = key_force.y * 6;
      
      vec_accelerate(vMove, vSpeed, vForce, 0.5);
      
      c_move(player, vMove, NULL, IGNORE_ME | IGNORE_PASSABLE);   
      player.pan -= key_force.x * 6 * time_step;
      
      if (ent_collided == TRUE)
      {
         if (colliding_entity != NULL)
         {
            VECTOR forward, angle; 
            vec_set(angle, colliding_entity.x);
            vec_sub(angle, player.x);
            
            vec_to_angle(angle, angle);
            
            vec_set(forward, vector(100, 0, 0));
            vec_rotate(forward, angle);
            
            pXent_addvelcentral(colliding_entity, forward);
         }
         ent_collided = FALSE;
      }
      
      wait(1);
   }
}

© 2024 lite-C Forums