[SOLVED]Simple Movement

edited October 2011 in Help request
I'm trying to get simple movement with collision detection going. From my reading, i found that simply changing the object's position with orxObject_SetPosition may mess with the physics engine (and thus, with collision detection, which has to be very accurate for the type of game I'm making). I noticed that orxPhysics has its own SetPosition, but I can't figure out how to get an orxPHYSICS_BODY pointer. Also, will that screw things up too?

I don't want to have physics applied to the player, I just want movement and collision detection.

Comments

  • edited October 2011
    Unless I'm terribly mistaken, you're looking for something like orxObject_SetSpeed():
    orxVECTOR speed;
    orxOBJECT *myobject = orxObject_CreateFromConfig("SomeObject");
    
    
    orxVector_Set(&speed, 100, 0, 0);
    orxObject_SetSpeed(myobject, &speed);
    

    (EDIT: So yes, meant to say, this will get the object moving towards the right of the screen, &c.)
  • edited October 2011
    Thanks. Got it working. Now I just need to stop the object from moving past the screen's borders... and allow other objects to do so. I'll see what I can dig up on that later.
  • edited October 2011
    I often just place a colliding body at either edge of the screen, and listen for physics events; if I catch such an event and it's associated with one of these "barriers," I act accordingly (loop the object to the other side of the screen, or some such).

    You could also make your objects Solid, which would make them stop once they hit such a barrier.

    Or, of course, you could just poll your objects for their position every frame in your update() call.

    Basically, there are several options ;)
  • edited October 2011
    What newton64 said. :)

    A small precision: calling SetPosition directly on physics objects wouldn't have worked either as it breaks the contacts tracked by Box2D everytime you do that. Also if you need to access any structure stored on an orxOBJECT, you need to use the helper macro orxOBJECT_GET_STRUCTURE(), in this case it'd be orxOBJECT_GET_STRUCTURE(MyObject, BODY).
  • edited October 2011
    Ah, thanks for that. You guys are really helpful!
  • edited January 2012
    iarwain wrote:
    What newton64 said. :)

    A small precision: calling SetPosition directly on physics objects wouldn't have worked either as it breaks the contacts tracked by Box2D everytime you do that. Also if you need to access any structure stored on an orxOBJECT, you need to use the helper macro orxOBJECT_GET_STRUCTURE(), in this case it'd be orxOBJECT_GET_STRUCTURE(MyObject, BODY).

    That doesn't work since it returns a orxBODY instead of a orxPHYSICS_BODY but then maybe i don't know what I'm talking about. I'm new to both C++ and orx. I'm trying to use orxPhysics_ApplyImpulse to get my spaceship moving but first of all I can't get a orxPHYSICS_BODY to put into it and second I have no idea if this is a good thing to do at all.

    //AlgoJerViA
  • edited January 2012
    Hmm I could typecast it to orxPHYSICS_BODY so this i the code right now...
    orxVECTOR Impuls;
    orxVector_Set(&Impuls, 100, 100, 1);
    
    orxVECTOR Point;
    orxVector_Set(&Point, 100, 100, 1);
    
    orxPhysics_ApplyImpulse ( (orxPHYSICS_BODY*) pstSpaceShipBody, &Impuls, &Point );
    

    And of course this doesn't work at all (it compiles but nothing happens to the spaceship), probably mostly because I have no idea about what I'm doing with the vectors and if the typecasting is OK to do.

    //AlgoJerViA
  • edited January 2012
    What are you trying to do? You might want to create a new thread since this one is marked solved. Describe your problem as well as you can, and we'll try to help you get it working the way you want to.
  • edited January 2012
    Just a quick precision, don't type cast an orxBODY * to orxPHYSICS_BODY *, you're likely to end up corrupting memory by doing so. :)

    And you want to use orxBody_ApplyImpulse and not orxPhysics_ApplyImpulse. The whole orxPhysics API is mostly used internally only and everything has been wrapped in the orxBody or even orxObject modules.

    As sonicbhoc said, it's much better to open a new thread and I just saw yours so I'm going to reply to it shortly.
Sign In or Register to comment.