Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Robert Sachse · Mar 10, 2011 at 04:24 PM · playerspaceshipalignmentinside

How to realize a moving, rotating Spaceship with a moving FPS-like Charakter inside?

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Robert Sachse · Mar 11, 2011 at 09:16 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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Adam_Benko · Oct 30, 2018 at 03:01 PM 0
Share

Could you please share a script that you used for this ? Thanks.

avatar image Adam_Benko · Oct 30, 2018 at 05:59 PM 0
Share

I made player to be a child of gameobject, that is a child of a Ship. However, I cant move with my player, since in update method of playerscript, position is set to holdingObject's position. How did you solve this problem ?

avatar image
0

Answer by AngryOldMan · Mar 10, 2011 at 04:34 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 rigidbody.isKinematic = true; which activates when your player is parented to the ship and of course false when you unparent him (assuming you unparent him at all)

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Robert Sachse · Mar 10, 2011 at 04:45 PM 0
Share

I want to make a multiplayer game in which several players can act together on 1 ship. ^^ Therefor I need to calculate where the ship is moving while the players are inside. The problem with activating kinematic when the player is inside a ship is simple, that he will not collide correctly with some other kinematic objects like doors if the ship is moving fast. For this reason I need continious dynamic collision detecting and this is only working, if 1 object is nonkinematic, which is the player. So thanks for your answer, but that's not the solution for this complex issue.

avatar image AngryOldMan · Mar 10, 2011 at 04:47 PM 0
Share

okay I understand that, so why does your ship need to move when people are on it? what about the 1st half of my reply?

avatar image Robert Sachse · Mar 10, 2011 at 05:49 PM 0
Share

Well, other players or NPCs in other Ships in Space should be able to see the ship moving, collide with it, fire on it, etc... and this calculation needs to go on while the player is inside. So I thought the best solutions is just to put him realy inside the ship and just let the game run the scene, switch cameras&controls when flipping insideout or otherwise. $$anonymous$$aybe there is a better solution to this. I also have a script that sets the ship to the floating origin and moves the world, but there are physics and camera issues, so I just use it after 1000 units in space to prevent spartial jitter.

avatar image AngryOldMan · Mar 10, 2011 at 07:41 PM 0
Share

so what about destroying (or hiding) the player after it gets into the space ship then instantiating it (or transform position then reveal) when players get out?

avatar image
0

Answer by Robert Sachse · Mar 10, 2011 at 06:13 PM

Here is some code I used in the script attached to the player:

var playerParent : GameObject;

function Awake () { transform.parent=playerParent.transform; }

function Update () {

if (lastPosition.magnitude==0) { lastPosition = transform.localPosition; } transform.position = transform.root.position+lastPosition; }

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 (:

var X : float; var Y : float; var Z : float;

 Y += (playerDistance.y*Mathf.Cos(shipRotationAngles.x) - playerDistance.z*Mathf.Sin(shipRotationAngles.x));
 Z += (playerDistance.y*Mathf.Sin(shipRotationAngles.x) + playerDistance.z*Mathf.Cos(shipRotationAngles.x));
 X += (playerDistance.x*Mathf.Cos(shipRotationAngles.y) + playerDistance.z*Mathf.Sin(shipRotationAngles.y));
 Z += (- playerDistance.x*Mathf.Sin(shipRotationAngles.y) + playerDistance.z*Mathf.Cos(shipRotationAngles.y));
 X += (playerDistance.x*Mathf.Cos(shipRotationAngles.z) - playerDistance.y*Mathf.Sin(shipRotationAngles.z));
 Y += (playerDistance.x*Mathf.Sin(shipRotationAngles.z) + playerDistance.y*Mathf.Cos(shipRotationAngles.z));

var newVector = Vector3(X,Y,Z);

...and then I could do:

transform.position = transform.root.position+newVector;

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).

Any ideas?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Dynam1ke · Jun 09, 2014 at 08:56 AM

Im having the same issue as you had. could you please give more detail about how you resolved your issue? thanks in advance

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Independently moving Rigidbody inside a moving Rigidbody 1 Answer

Detect if player is in structure (or in range) 1 Answer

Code working for tutorial guy but not for me. 1 Answer

Is it possible to open a unity game/application on an iphone/ipad inside a regular app? 2 Answers

How to create a hollow sphere world? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges