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 boxing_rex · Oct 17, 2014 at 06:36 PM · c#transformplayerlateupdate

[Closed]transform.position not updating fast enough

I have my gun following my player using transform.position, but when I move the gun glitches back and forward because it is simply not fast enough to keep up with my player and look somewhat decent. I have been getting around this before by setting the gun to be a parent of the camera object, however now that I have a gun pick up script this is no longer a viable option. Here is the code that updates the guns position to the players transform:

 Vector3 centerOfCamera = playerCamera.GetComponent<Camera>().ViewportToWorldPoint(new Vector3(0.5f,0.5f, playerCamera.GetComponent<Camera>().nearClipPlane));
 transform.position = Vector3.Lerp(transform.position, centerOfCamera + Quaternion.Euler(targetXRotation, targetYRotation, 0) * new Vector3(0, 0, currenRecoilZPosition), hipToAimSpeed);

All of this code is placed within the void lateUpdate() function.

Thanks for reading my question and I hope that one of you can lend a helping hand.

Comment
Add comment · Show 5
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 DocMcShot · Oct 17, 2014 at 06:43 PM 0
Share

Have you tried to place this code in the regular Update() and see if that helps?

avatar image Habitablaba · Oct 17, 2014 at 06:44 PM 0
Share

I'm not sure why having a pick up script would make your previous solution no longer viable.

avatar image boxing_rex · Oct 17, 2014 at 06:52 PM 0
Share

@Doc$$anonymous$$cShot, It helps a little, but it still very buggy and jumpy. @Habitablaba, I just have always assumed that there is a better way of doing things, I mean if there is no fix then I am happy putting the gun as a child of the camera.

avatar image robertbu · Oct 17, 2014 at 06:53 PM 0
Share

This sounds more like a script order problem rather than a speed problem. Consider putting the code in LateUpdate() or specifying the execution order of scripts:

  Edit > Project Settings > Script Execution Order
avatar image Habitablaba · Oct 17, 2014 at 07:00 PM 0
Share

I think having a parent/child relationship between the gun(or player, even) and the camera is a fine idea. It is certainly simpler than trying to force the two to stay together some other way, and at the end of the day, it works :)

0 Replies

· Add your reply
  • Sort: 

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

30 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Third person movement similar to Max Payne 1 Answer

Help regarding World-Local Transfrom Rotation? 1 Answer

How to allow movement of game object to certain points only 1 Answer

Most efficient way to get a reference to a gameobject near NPC? 1 Answer

Unity 3d(Space) Questions 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