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 debu · Oct 16, 2014 at 11:22 AM · transform.translate

Transform.Translate | Self | World

Hi,

I am working on a VR application with Google Cardboard, where in I am trying to simulate movement on click of the magnetic button.

My question is related to the movement, where in I am trying to move the user with Head Bobbing to simulate realistic walking. Following is the code snippet:

 public class ControlCamera : MonoBehaviour {
 
     float timer = 0.0f; 
     public float bobbingSpeed = 0.18f; 
     public float bobbingAmount = 0.2f; 
     public float midpoint = 1.0f; 
     public float horizontal = 10.0f; 
     public float vertical = 10.0f; 
     
     // Update is called once per frame
     void Update () 
     {
         float waveslice = 0.0f; 
 
         if (Sensors.isMove) 
         {
             // transform.Translate (Vector3.forward * Time.deltaTime);
 
             if (Mathf.Abs(horizontal) == 0 && Mathf.Abs(vertical) == 0) 
             { 
                 timer = 0.0f; 
             } 
             
             else 
             { 
                 waveslice = Mathf.Sin(timer); 
                 timer = timer + bobbingSpeed; 
                 
                 if (timer > Mathf.PI * 2) 
                 { 
                     timer = timer - (Mathf.PI * 2); 
                 } 
             } 
             
             if (waveslice != 0) 
             { 
                 float translateChange = waveslice * bobbingAmount; 
                 float totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical); 
                 totalAxes = (float) Mathf.Clamp (totalAxes, 0.0f, 1.0f); 
                 translateChange = totalAxes * translateChange; 
                 
                 transform.Translate(Vector3.forward * Time.deltaTime);
                 transform.Translate(new Vector3(0.0f, (midpoint + translateChange), 0.0f), Space.World);
             } 
             
             else 
             { 
                 transform.Translate(Vector3.forward * Time.deltaTime);
                 transform.Translate(new Vector3(0.0f, (midpoint + translateChange), 0.0f), Space.World);
             }
         }
     }
 }


I am trying to integrate the forward translate with the head-bobbing in the above code, one translate is Space.Self (forward motion) whereas the other translate is Space.World (head-bobbing).

Whenever I am trying to do both the things in separate lines of code only the head-bobbing is done whereas the forward translate doesn't happen.

Link to head bobbing

Any help is appreciated, thanks in advance!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by debu · Oct 17, 2014 at 05:27 AM

Both the line of code i.e.,

 transform.Translate(Vector3.forward * Time.deltaTime);
 
 transform.Translate(new Vector3(0.0f, (midpoint + translateChange), 0.0f), Space.World);
 } 


are working fine independently.

thanks, D

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 debu · Oct 21, 2014 at 10:11 AM 0
Share

I can't find a clue as per what is going wrong, any clues or leads would be very helpful.

thanks again, D

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

Midair Strafing 3 Answers

Align Parent object using child object as point of reference 3 Answers

Problem with a RigidBody and IsKinematic... I think 1 Answer

Player character moves without controller input 2 Answers

Is it possible to do inverse transformations, instead of moving complex groups of objects? 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