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
1
Question by AndrewS 1 · Sep 26, 2010 at 03:15 AM · transformcharactercontrollervehicle

Attaching player transform to vehicle transform not moving player position

I am beginning work on a FPS that allows the player to enter/exit vehicles. I have a simple plane in the works. When the player touches a trigger collider attached to the plane, I want to attach the player to the plane. I am using a Character Controller for the player. The player doesn't have a rigidbody. The plane is a rigidbody that I control by adding forces.

I am setting the player tranform's parent to that of the plane; however the plane takes off and the player doesn't move. The player's transform magnitude rapidly increases from zero as the plane flies away and the player gameobject is in the plane's transform hierarchy, so the 'attach' is working. Once the player touches the plane I don't adjust its position at all.

//instant take off for now plane.transform.position = new Vector3(1000, 100, 700); plane.transform.rotation = Quaternion.AngleAxis(320, Vector3.up); plane.rigidbody.velocity = plane.transform.forward * 50;

//attach player to plane and put them in the cockpit position transform.parent = plane.transform; transform.localPosition = plane.OwnerPosition; //currently 0,0,0

It seems that the player's localtransform is relative to the plane, but the player isn't attached as such.

Do I actually need to reset the player's transform.localPosition every update? I tried this and I found that when the plane was going really fast, the player would lag behind a bit.

Thanks for your help.

Edit: Updating the player's position to the plane's cockpit position (0,0,0 at the moment) in Update rather than FixedUpdate seems to help with the player lagging behind, though I need to test that further. I'm still not sure if this is the best way to go though.

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
1

Answer by Paulius-Liekis · Sep 27, 2010 at 09:31 AM

Sounds, weird attaching should just work (you're doing something like this: player.transform.parent = plane.transform), right? Maybe there is some script which is affecting players position (like some physics/character controller)?

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 Wolfram · Sep 27, 2010 at 10:43 AM

In general, a

player.transform.parent = plane.transform;

should suffice. You don't need (and don't want to!) reset player.transform.localPosition after that, because this value is automatically adjusted when you do the reparenting, so that "player" does not change its global position in world coords (The above line of code does exactly the same thing as dragging the player onto the plane in the hierarchy tab).

The problem you're experiencing sounds more like a collision/physics problem. I'm not sure how physics objects re supposed to behave if you attach them to one another, and apply a force to the other.

My first guess would be, the physics engine is very picky with large differences in positions between frames (e.g., trying to hit a tennis ball with a racket), and will not recognize the collision if the velocity is too large. Try to see if your problem persists if you use very low velocities for your plane. If that fixes your problem, use this script (forum discussion).

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

Does moving a charactercontroller via it's transform hurt performance? 1 Answer

How do i move CharacterController toward the direction its facing? 0 Answers

How to rotate an object without transform.Rotate 1 Answer

CharacterController.Move Not Corresponding to gameobject.transform.rotation 1 Answer

Transformers 1 Answer


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