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 Psilobe · Mar 05, 2013 at 06:18 PM · rotationmovementtransform

Object moving sideways when translating using forward vector.

I'm trying to move towards a point and I'm currently calling two functions during every update.

 void moveForward()
     {
         transform.Translate(transform.forward*speed*velocity);
     }
 
 void turnTowards()
 {
     Vector3 desired = point -transform.position;
     Vector3 rotation = Vector3.RotateTowards(transform.forward,desired,turnSpeed*Time.deltaTime,1);
     transform.rotation = Quaternion.LookRotation(rotation);
 }

The object rotates as I want but doesn't move correctly, using only the rotate function points the object at the target. It is as if the transform.forward vector is wrong. The objects gets to the target point but the it looks wrong. I call rotate before movement.

I would expect the object to rotate a bit, move a bit forward in the new direction, rotate, move, rotate, move, etc...

It looks like of move and forward uses two different forward vectors which slowly syncs, only way I can describe the way it looks.

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
Best Answer

Answer by robertbu · Mar 05, 2013 at 06:59 PM

If 'velocit'y is a vector, it will change forward. Forward is the side of your model facing positive 'z' when there is no rotation (0,0,0) Your turnTowards using transform.forward is not code I've seen before and I think it is not following the arc you want it to. Here is how I typically see rotation over time coded:

 void turnTowards()
 {
     Vector3 desired = point - transform.position;
     Quaternion q = Quaternion.LookRotation(desired);
     transform.rotation = Quaternion.RotateTowards (transform.rotation, q, turnSpeed*Time.deltaTime);
  

}

Comment
Add comment · Show 3 · 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 Psilobe · Mar 05, 2013 at 07:37 PM 0
Share

$$anonymous$$y model is rotated so it's aligned with the forward vector but I still get the same sideways sliding with your rotation code.

avatar image robertbu · Mar 05, 2013 at 08:31 PM 0
Share

Can you describe what you want? Are you looking to move directly to the goal while rotating? Here is code that moves towards the goal in a line (though unlike yours, it stops at the goal):

 void moveForward()
     {
        transform.position = Vector3.$$anonymous$$oveTowards (transform.position, point, speed * Time.deltaTime);
     }
avatar image Psilobe · Mar 06, 2013 at 02:09 PM 0
Share

I want my object to turn and moce towards the target, in this case my object is a boat. I dont want it to just turn on the spot but move while it turns but as I've said with everything I've tried I just get the same behavior.

But I figured out a way to move forward. I tried to update position by either translating with the direction vector or adding the direction vector too the position. As you said forward would be the models z axis but I moved along the x axis by doing this, by using translate(0,0,speed*Time.delta) I got forward motion. Thanks for the help!

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

10 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

Related Questions

Ball Rolling Animation Not Working Properly 0 Answers

Rotating an object towards target on a single axis 2 Answers

The way to approach DodgeRoll 0 Answers

Face direction to move in 2 Answers

How can I rotate my player to look at the direction my Joystick is pointing to? (Top-Down 2D) 3 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