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 KoshX87 · Oct 17, 2012 at 01:15 PM · cameratransformrotate

Can the Camera Smoothly rotate AFTER a button is pressed? (Javascript)

I don't know whether this is a stupid question or not because I am pretty good with unity. I am trying to find out how i can smoothly rotate my camera AFTER a button has been pressed.

The game that I am making, starts off with a main menu. On this menu there is a choose character button which the player will press to choose his/her character. After the player has pressed this button, the camera is supposed to rotate clockwise (y axis turn) to face the available characters. I have found codes to rotate the camera, but the rotation occurs immediately after the button is pressed, so it ends up the same as just moving my camera's position. I will put the code down for my camera rotating instantly and i will accept any advice or help anybody is willing to offer:

 var ingamecamera: GameObject;
 function OnMouseUp(){
     ingamecamera.transform.Rotate(0,90,0);
 }

The code above is placed on my button so that when it is pressed the game object of my camera will turn.

Comment
Add comment · Show 9
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 whydoidoit · Oct 17, 2012 at 01:17 PM 0
Share

You want to use Lerp or Slerp to move it smoothly. This has an example of smoothly moving an object.

avatar image Fattie · Oct 17, 2012 at 01:17 PM 0
Share

http://unitygems.com ... "beginner" article ... section on timers and Invoke()

avatar image Fattie · Oct 17, 2012 at 01:25 PM 0
Share

just the man I was looking for! .. @whydo ..

if you look at your Invoke()/etc section in the beginner/ meisterwerk.

notice that the example is indeed somewhat advanced ....... using invoke(s), from update, locks, and so on. looking at the OPs question here for example (and there have been about 3 others the same, incredibly)

I was thinking, maybe there should be just in a few lines "simplest example" of invoke, prior to your advanced example???

so literally how to put an "invoke" in start and "have it do something in a few seconds". possibly your immediate large example is too advanced? Food for thought. You the man.

I admire the OP here's consistent, clear code and thought processes. But nobody's ever told the bloke how to make a timer!

avatar image whydoidoit · Oct 17, 2012 at 01:46 PM 0
Share

Agreed and done. Also (sorry) added one example of where a coroutine would be useful for this kind of thing ;)

avatar image whydoidoit · Oct 17, 2012 at 01:47 PM 0
Share

@$$anonymous$$oshX87 in that link both @Fattie and I posted I've added an example of rotating an object over time.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by KoshX87 · Jan 04, 2013 at 08:32 PM

 var myTransform: Transform; //Object you want to rotate
 var target: Transform; //The game object that you want to face
 var rotationSpeed: float = 5;
 myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*TimedeltaTime);

This answer is quite late and i realise that, but i did manage to fix it a while a go, but noone had put the answer up here. If for that code above, you just put the last line into a onMouseUp, kind of function it will make the camera face the target whenever the mouse is clicked with a slow or fast rotation speed based on the rotationSpeed variable. I am not using it with a click anymore and I am actually using it on an enemy(the myTransform is set to an enemy prefab) to move from each waypoint. For those writing a waypoints script and you want to know how to make the enemy move towards the target after it has rotated, heres the script:

 var moveSpeed: int = 10; //can be whatever you want
 myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
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

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

Parent an objects position without its rotation 1 Answer

Make player face same direction as camera. 4 Answers

Moving Camera on player stop then move and rotate to separate point? 0 Answers

camera move x axis 2 Answers

Spawned an object but it faces the wrong way. What's the fix? 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