Hi,
I am currently developing a space game with the BEPU Engine.
The player can walk through his spaceship and pick (dynamic) objects up and there is my problem.
I've set the whole ship to dynamic and gave him a huge mass value. The ship itself is not affected by gravity but the items in it are.
Now the items (and the capsule for the camera) are pushing the ship around and that's what I want to avoid.
I've tried all collisiongroups but I think that's not what I need.
So I need the collision (object->ship) but the dynamic objects inside should not affect the ships transformation.
But I also need to have the ship as a dynamic entity because the ship can collide with other ships.
Hope someone can help me.
Many thanks in advance!
MaxKhl
Kinetic for specific entities
Re: Kinetic for specific entities
Here's a few options, sorted roughly from not-so-good to better:
1) Make the interior of the ship separate from its physical representation. In essence, it would be a bunch of static rooms that you teleport into when you enter the ship while the exterior of the ship floats around. This is hacky and limits game design, though.
2) Try to conditionally combat contact-sourced impulses by applying equal magnitude counter impulses, but this could get painful (e.g. is this contact's impulse due to gravity, or an impact?).
3) Any gravity which does not affect the ship must be generated by the ship. Create your own gravity field which grabs the object within the ship and applies a force to them. Apply the equal and opposite force to the ship. Expect some drift with this approach. You can fight the drift by being selective with which objects you apply force to (players stuck to the ground with magnetic boots or something don't need gravity) and damping the angular motion of the ship. If the ship has engines capable of controlling angular motion, the drift can easily be combated in full (target angular velocity of zero unless user input specifies otherwise).
1) Make the interior of the ship separate from its physical representation. In essence, it would be a bunch of static rooms that you teleport into when you enter the ship while the exterior of the ship floats around. This is hacky and limits game design, though.
2) Try to conditionally combat contact-sourced impulses by applying equal magnitude counter impulses, but this could get painful (e.g. is this contact's impulse due to gravity, or an impact?).
3) Any gravity which does not affect the ship must be generated by the ship. Create your own gravity field which grabs the object within the ship and applies a force to them. Apply the equal and opposite force to the ship. Expect some drift with this approach. You can fight the drift by being selective with which objects you apply force to (players stuck to the ground with magnetic boots or something don't need gravity) and damping the angular motion of the ship. If the ship has engines capable of controlling angular motion, the drift can easily be combated in full (target angular velocity of zero unless user input specifies otherwise).
Re: Kinetic for specific entities
Thanks for your fast answer.
I guess 1 and 2 are not the right solutions.
3 could work for me but looks kind of hard to implement.
From your answers I got another idea but not sure if this could work.
Maybe it is possible to add a second entity for the ship that is set to kinetic and I copy the WorldTransformation of the dynamic ship entity to the kinetic (or apply a impulse).
With the right collisionrules I could avoid collision between the two ship entities but provide a object to collide for the dynamic items and the other ship entity could deal with objects on the outside.
In this case I could give the dynamic ship entity a regular box for collision.
I'd like to try it now but don't have the files here. Could this be possible in theory?
I guess 1 and 2 are not the right solutions.
3 could work for me but looks kind of hard to implement.
From your answers I got another idea but not sure if this could work.
Maybe it is possible to add a second entity for the ship that is set to kinetic and I copy the WorldTransformation of the dynamic ship entity to the kinetic (or apply a impulse).
With the right collisionrules I could avoid collision between the two ship entities but provide a object to collide for the dynamic items and the other ship entity could deal with objects on the outside.
In this case I could give the dynamic ship entity a regular box for collision.
I'd like to try it now but don't have the files here. Could this be possible in theory?
Re: Kinetic for specific entities
It would work so long as you have easy control over when something is an 'inside object' versus an 'outside' object. For example, a ship ramming another ship should be treated dynamically, but tinier ships landing in a big ship's hangar would need to collide with the kinematic version of the ship to avoid gravity related issues.
Also, make sure that the position, orientation, linear velocity, and angular velocity are all copied over to the kinematic entity. Copying position and orientation alone is not sufficient for collision response to behave properly.
Also, make sure that the position, orientation, linear velocity, and angular velocity are all copied over to the kinematic entity. Copying position and orientation alone is not sufficient for collision response to behave properly.
Re: Kinetic for specific entities
Perfect. Yeah I know exactly what is inside. I got a separate closed model of the ship to detect if a item is inside or not.
That's a good advice. Think I would have just copied the position and orientation and wondered why it's not working.
I'll try that tomorrow and post if it's working but I am confident.
Thanks for your help!
That's a good advice. Think I would have just copied the position and orientation and wondered why it's not working.
I'll try that tomorrow and post if it's working but I am confident.
Thanks for your help!
Re: Kinetic for specific entities
Tried it and it works fine!
But now I got another Problem. The items in the ship are sliding away when i try to move it. (with ApplyImpulse)
Is there any chance to make their worldtransformation dependend to the ship-matrix.
But now I got another Problem. The items in the ship are sliding away when i try to move it. (with ApplyImpulse)
Is there any chance to make their worldtransformation dependend to the ship-matrix.
Re: Kinetic for specific entities
That's the correct physical behavior, so fighting against it will require some hacks. You could apply an acceleration to the objects inside the ships equal to the acceleration experienced by the ship.
At this point, though, it may be easier to just use the 'static ship interior' approach I mentioned earlier. Separating the interior into an entirely different area means that occupants won't feel any physical effects from the spaceship's exterior or motion unless explicitly programmed to do so.
At this point, though, it may be easier to just use the 'static ship interior' approach I mentioned earlier. Separating the interior into an entirely different area means that occupants won't feel any physical effects from the spaceship's exterior or motion unless explicitly programmed to do so.