First, sorry for my bad english. ;)
Okay, I got this:
1 transform with an rigidbody attached to it without use of gravity in non-kinematic mode<-- that's my Spaceship This transform has a collider (eg Boxcollider).
And I got a player, which has a transform, a collider and also a rigidbody without gravity in non-kinematic mode, so i can use continious dynamic collisiondetection, which i need, if the ship is moving fast. Inside the Ship are some other parented transforms with kinematic rigidbodies and colliders like doors, to which the player should collide correctly, even on high speed.
Now the matter is, that the player wont follow the ship, even if I parent him to the ship because of the non-kinematic rigidbody which i need to have for correct collisions. (Otherwise the collisiondection will fail on high speed due float inaccuracy.)
So I tried to "software parent" him with setting his position to the position of the spaceship + his local position. That works as long as the ship is not rotated.
If the Ship rotates, I need to rotate the local distance positionvector of the player to the rotation of the ship and I don't have a clue how to manage that.
So, has anyone an idea to solve this "Player inside Ship"-problem?
I've allready written my own charaktercontroller to handle the situation inside the ship (gravity aligns to the ship, jumping as also, ...), but for this point I have no solution.
asked Mar 10 '11 at 04:24 PM
Solved the problem my self with 1 easy trick.
Just added another empty gameobject to the ship and let this control the players position and rotation. In update() of the real playerobject script I just set its position to the empty gameobject which is parented to the ship.
So easy, but it was hard to find out this solution.
answered Mar 11 '11 at 09:16 PM
why does your ship need to move when the player is inside? if the player isn't visible you could just destroy him and assume control of the ship then instantiate him when your done controlling the ship. Or if you control your player while inside the ship but still want your ship to "move around" you could try moving the rest of the level around the static ship OR you could put animating textures in the windows to simulate outside movement.
Another fix if you definatly have to go down the route you described just code something like
answered Mar 10 '11 at 04:34 PM
Here is some code I used in the script attached to the player:
Works fine, as well as the parent is not rotating.
To rotate lastPosition (the position of the player inside the ship) correct to the ship, I need the correct rotationangles of the ship. Then I can rotate lastPosition (as playerDistance in this example) with this (:
...and then I could do:
So the question is, how to get the right angles? transform.root.rotation is a quaternion which gives wrong angles if I want them to use with this script (real 360 needed).