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 pheekle · Aug 14, 2013 at 05:09 AM · camera rotaterotate objectbasic programmingclicktomove

Ship rotate to look at over time

So Robertbu has been super helpful with getting my basic game play setup. Basically I want to rotate the ship to 'look at' the new position it will be moving to over time. I do not want it to stop look in new direction then continue to move. I just want it to turn slowly into the direction while its moving. However when it's stationary, I don't want it to move until its fully looking in that direct.

Something on the lines like this https://www.youtube.com/watch?v=hAVXSBnsEtA

Demo: http://cerberium.com/test/Test.html

 #pragma strict
  
 var speed = 35.0;  // Degrees per second
 var delay = 2.0;
 private var direction = Vector3.zero;
 private var qTo = Quaternion.identity;
 private var timeStamp : float;
  
  
 function Update () { 
  
     if (Input.GetMouseButtonDown(0)) {
        var mousePos = Input.mousePosition; 
        mousePos.z = 1000; // select distance = 10 units from the camera
        var worldPos = Camera.main.ScreenToWorldPoint(mousePos); 
  
        direction = (worldPos - transform.position).normalized; 
        timeStamp = Time.time + delay;
        qTo = Quaternion.LookRotation(direction);
        }
  
     transform.rotation = Quaternion.RotateTowards(transform.rotation, qTo, speed * Time.deltaTime);
  
     if (direction != Vector3.zero && timeStamp < Time.time)
       transform.position += direction * Time.deltaTime;
  }
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 2d4Games · Aug 14, 2013 at 07:57 PM

At line 18 you're setting the timeStamp to be 2 seconds in the future, and at line 25 you're making the if statement not get triggered until those 2 seconds pass.

From what I see, after you click, your ship would stop having its position transformed, and then start again after 2 seconds.

What is the timeStamp meant to be doing, by the way?

Comment
Add comment · Show 9 · 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 pheekle · Aug 14, 2013 at 08:01 PM 0
Share

Initially I wanted it to point to the position where you click, then move but only when its stationary. Now I want it to turn while its moving like a spaceship would to the new location. The video I posted, is what I'm shooting for.

avatar image 2d4Games · Aug 14, 2013 at 08:30 PM 0
Share

Ah, alright. In that case, just take out the timeStamp check, and it should work.

avatar image pheekle · Aug 14, 2013 at 09:28 PM 0
Share

I did that. I also updated the webplayer link. Click in a forward position, then click behind it. It goes straight back, and its moving before its even completely rotated in that direction. That's why I'm trying to get it so it makes a "U Turn". A smooth transition while turning around. Sorry for the horrible description.

avatar image 2d4Games · Aug 14, 2013 at 10:20 PM 0
Share

Ah I see what you mean now. You need to add an acceleration to the direction, so that ins$$anonymous$$d of just instantly switching direction from one point to another, the transformation goes slowly from one direction to the other.

Save the point that the person clicks as a different variable, and calculate the time it takes for the Quaternion to finish rotating. Then calculate the acceleration required to reach the correct x, y, and z components of the direction, and apply them until the Quaternion has finished rotating. This should give the ship a nice looking little curve when changing direction.

avatar image 2d4Games · Aug 14, 2013 at 10:24 PM 0
Share

Or better yet (and less complicated), just change direction to the transform.forward of the cube. The cube will always go in the direction that it is facing.

Show more comments

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

17 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

Related Questions

Jittering effect when moving character and camera 2 Answers

How do I follow a gameobject with the camera 3 Answers

How does one use quaternion.euler(x,y,z) to rotate on y axis? 2 Answers

How to rotate a camera relative to the player ? 0 Answers

Problem with Constraint Camera Rotation C# 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