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
0
Question by r_chevallier · Jul 14, 2015 at 11:20 PM · transformvector3transform.positioneuleranglesforward

Turn and Move Foward 1 Unit relative to Objects local direction

Hello,

How can I modify this section of my script so my game object moves foward 1 unit relative to its rotation angle?

In this part of the script my object suppose to turn right and move forward 1 unit base on trigger events.

Every "right turn" will be relative to the game object's new position/direction from any previous right turn. So every trigger will set off an additional 90 degree turn from the last rotation.

Instead my object turns right and my object does not move foward in the Objects local direction but in the direction of the newVector 3(1,0,0) which is from what I understand always a constant World direction no matter which way your game object is facing.

// Turn to the right

             print("right");
             localEulerAngle = new Vector3();
             localEulerAngle.y = 90;
             thisTransform.eulerAngles = localEulerAngle;
             
             // Set the new target position to move to
             targetPosition = thisTransform.position + new Vector3(1, 0, 0);

             // Make sure the player lands on the grid 
             targetPosition.x = Mathf.Round(targetPosition.x);
             targetPosition.z = Mathf.Round(targetPosition.z);





Thanks in Advance.

Comment
Add comment · Show 1
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 maccabbe · Jul 15, 2015 at 12:06 AM 0
Share

most likely you want transform.forward or transform.right

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SirAstral · Jul 15, 2015 at 12:50 AM

Here is something I tested.

// This will rotate the object to the right 1 degree. If you want it to rotate so that it faces right you would use 90 where the 1 is at. to turn it left put a - in front for minus.

 this.transform.Rotate(new Vector3(0,1,0));

// This will move the object forward which is by default its Z axis.

 this.transform.position = this.transform.position + (transform.forward + new Vector3(0,0,1));



If you put both of these together in the void Update () method you will see the cube go forward as it turns to the right. This code will move your object how you are wanting. But you will have to figure out what logic calls this movement.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Trouble converting transform.position to C# 1 Answer

How do I change one value of a vector? 2 Answers

Euler Angles and Vectors 3 Answers

fixed distance for Vector3.moveTowards ? 1 Answer

How to anticipate the Vector3.forward of the enemy? 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