Creating a rigidBody at a point in camera space?

Post Reply
jimjamjack
Posts: 39
Joined: Tue Jan 31, 2017 8:07 pm

Creating a rigidBody at a point in camera space?

Post by jimjamjack »

Hi, I can currently create a rigidBody at world space position (given a specific x, y and z).

This works fine if my bullet model is just randomly placed in the scene, but I'm now attempting to fire bullets from the end of my gun (which is attached to the gun by removing the viewMatrix multiplication in my MVP uniform, so I'm doing the same for my bullets since they need to come from the gun which can be facing any direction).

Is there a way to create a rigidBody in camera space, then move my bullet to that location?
Or maybe it's best to somehow draw the bullet in camera space, but as you move away, it remains there in world space, then simply take it's position?

I'm unsure how to approach this, so any help is appreciated. Thanks.
Last edited by jimjamjack on Mon May 01, 2017 9:51 pm, edited 1 time in total.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Creating a rigidBody at a point in camera space?

Post by drleviathan »

You can slam the RigidBody transform directly, however if the body is dynamic and inactive when you do this then you should activate it:

Code: Select all

body->setWorldTransform(transform);
if (!body->isStaticOrKinematicObject() && !body->isActive()) {
    body->activate();
}
jimjamjack
Posts: 39
Joined: Tue Jan 31, 2017 8:07 pm

Re: Creating a rigidBody at a point in camera space?

Post by jimjamjack »

drleviathan wrote:You can slam the RigidBody transform directly, however if the body is dynamic and inactive when you do this then you should activate it
My issue is that when defining the motionstate, I can't give it an x, y and z value for its position since my bullet model is being drawn in camera space. If I just give it some world space coordinates, like my current player position, then the rigidBody is created just fine and falls as expected. Thanks.
Post Reply