Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Justin-Wasilenko · Aug 14, 2015 at 04:42 PM · cameramovementridgidbody

Move in direction camera is facing

I have a Google Cardboard object, with this script attached to the Head object and a Rigidbody componet:

 public class PlayerMovement : MonoBehaviour {
 
     public float thrust = 2.0f;
 
   void FixedUpdate()
   {
     transform.Translate(Camera.main.transform.forward * thrust * Time.deltaTime );
   }
 
 }

I'd like to constantly be moving in the direction I am looking. But using this script when I change my gaze direction my movement doesn't always follow.

Sometimes it works perfectly, and other times the movement is completely off depending on the build of the game.

Seems like a simple script, but maybe I'm not doing something correctly???

Comment
Add comment · Show 2
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 TRG96 · Aug 14, 2015 at 04:56 PM 0
Share

why are you using FixedUpdate? you are not dealing with a rigidbody so you can just use update. Try using transform.Translate(Camera.main.transform.forward * thrust * Time.deltaTime, Space.Self);

avatar image Justin-Wasilenko · Aug 19, 2015 at 06:59 PM 0
Share

Using Space.self does help in the editor. However whenever I build the game for Android I get very different movement then I do in the editor.

I am using FixedUpdate because I have a Rigidbody attached, like I stated above and I have a collider so when you are flying around you can collide with objects and not fly through them.

What can be the differance between in the editor and the build version for android?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by FortisVenaliter · Aug 19, 2015 at 08:09 PM

transform.Translate works in local coordinates. Camera.transform.forward is in world coordinates.

Rather than using the translate function, try just using transform.position += ...

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 Justin-Wasilenko · Aug 20, 2015 at 05:55 PM 0
Share
 transform.position += this.transform.forward * thrust * Time.deltaTime;

This works great, using Camera.main doesn't work with Cardboard because I just noticed that it's the head object that has the rotation values, not the $$anonymous$$ain Camera.

avatar image mattkell462 · Mar 09, 2018 at 12:01 AM 0
Share

how would we make this work if we want our camera to take directional inputs and change based off the direction we were looking?

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

27 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

Related Questions

How to smoothen movement of a child object? 1 Answer

Player walks to the right? 1 Answer

How to add Pinch to Zoom? 0 Answers

Camera Movement and angles 2 Answers

how to stop making script constantly want to look at the vector 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