Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
6
Question by bruno · Dec 26, 2009 at 02:26 AM · animationcollisionphysicslinking

how could a player (or an object) be moved onto and inside an animated vehicle?

What would be the best way(s) to have the player (and/or an object) move onto an animated object (translating and/or rotating ''vehicle'' for instance) and then be ''transported'' by that animated object while keeping its ability to be moved around by mouse/keyboard control until it 'steps off' that vehicle (like stepping on board of a moving ship, and sitting or walking around while being transported, until finally stepping off the ship)? Would anybody have achieved that sort of thing (or tried to..), and would there be any 'scripts' available for that? (or can it be achieved by applying physics, and in that case, how?) Thanks for any help; any idea or piece of advice would be welcome.

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

2 Replies

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

Answer by jashan · Dec 26, 2009 at 08:37 AM

Basically, all you need to do is put the player-object under the vehicle-object in the hierarchy. That can be done via Transform.parent. So if you have Transform vehicle and Transform player, to get into the vehicle, simply call

player.parent = vehicle;

Then, when the player leaves the vehicle, simply call

player.parent = null;

In the case where the player steps onto a car that he would control, you'd also need to transfer control (moving the player around with keyboard / joystick / mouse) from directly influencing the player to influencing the vehicle (and back). So, in that case you'd have some sort of "PlayerController"-class to which you either assign the player-object, or the vehicle-object. You might also change the state if the behavior of the vehicle is different from the behavior of the player (which is usually the case). Obviously, those are very game-specific things.

For the example of the ship in which the player can move around (what you asked for), that would be more like a typical moving platform: In that case, you would keep controlling the player but have it attached to the ship. Then, you just need to make sure that any movement of the player is based on Transform.localPosition instead of Transform.position. This is really where having Transform.localPosition shows its full benefit because using that, these kinds of things get very easy to implement.

In Traces of Illumination, I now do have moving platforms that the player can get onto; which is working quite nicely and wasn't too hard to implement. However, the scripts wouldn't help much because I still need to do a lot of stuff specific to that game; so they would be unnecessarily complex (it's networked multiplayer - so that adds a tremendous amount of complexity). But with the information above and the scripting reference, you should have a very good start. Feel free to ask any more specific questions along the way.

Comment
Add comment · Show 1 · 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 bruno · Dec 26, 2009 at 05:25 PM 0
Share

many thanks, I'll study your explanations for the moment and might be interested in 'networked multiplayer' info in a not so remote future.

avatar image
0

Answer by StephanK · Jan 06, 2010 at 04:02 PM

I guess parenting your objects Transform will certainly do the trick. But there is another way to do this if you don't want to mess with your hierarchy. You could also use a "Fixed Joint". This will attach your player to the moving object's rigidbody. The advantage is that you don't neet to change hierarchy. However this will only work if both objects have a rigidbody component.

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

No one has followed this question yet.

Related Questions

How to add physics to an animation? 3 Answers

Collision occurring when it should not! Help! 1 Answer

What is the best practice in handling scenes with 100+ rigidbodies and collisions on iOS? 1 Answer

Is there a way to use physics to keep a character from clipping through itself during an animation? 0 Answers

Help with 2D Hit Detection! 0 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