Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by SimonClintonIv · Jun 04, 2016 at 11:38 AM · rotationtransformpositiontracking

How can I make an object transform to given position and rotation

For example, if I want to move my object to x=10, y=5, z=2 position and rotate to x=45, y=0, z=45 rotation, how will I be able to do this using the following code transform.Translate(1f * Time.deltaTime, 0f, 0f); for position and using this code

transform.Rotate (new Vector3 (15, 30, 45) * Time.deltaTime); for rotation.

Comment
Add comment · Show 4
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 Eudaimonium · Jun 04, 2016 at 01:07 PM 1
Share

Translate will move the object by that amount, not to those coordinates. Same with Rotate.

Use:

 transform.position = new Vector3(10,5,2);
 transform.rotation = Quaternion.Euler(new Vector3(45,0,45));

(going by memory alone, not 100% sure on .Euler function, perhaps it's ".FromEuler" or something. Let Intellisense help you.

avatar image SimonClintonIv Eudaimonium · Jun 04, 2016 at 01:55 PM 0
Share

I already tried this, it works. I am using it for camera so I want a smooth movement. The player who is playing my game must see a smooth change in camera motion not a sudden change. But thanks for answering because the code you posted is shorter than my code. so I just want to see the movement of the camera while reaching the given position.

avatar image Eudaimonium SimonClintonIv · Jun 04, 2016 at 02:02 PM 0
Share

Oh I'm sorry, I missed this.

If that is the case, may I suggest looking to linear interpolation functions? https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html
https://docs.unity3d.com/ScriptReference/Quaternion.Lerp.html

The interpolation factor moves between 0.0f and 1.0f - simply move that via your update loop to have your camera transition from one place to another slowly over some time.

Show more comments

2 Replies

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

Answer by SimonClintonIv · Jun 07, 2016 at 02:41 PM

 using UnityEngine;
 using System.Collections;
 
 public class CamTrack : MonoBehaviour {
     public GameObject Player;
     public GameObject Camera;
     public static int global; //global variable
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 
     void LateUpdate()
     {
         //Default position
         if (Camera.transform.position.x < Player.transform.position.x) //move right
         {
             transform.Translate(1f * Time.deltaTime, 0f, 0f);
         }
 
         if (Camera.transform.position.x > Player.transform.position.x) //move left
         {
             transform.Translate(-1f * Time.deltaTime, 0f, 0f);
         }
             
         if (Camera.transform.position.z < Player.transform.position.z + -3) //move front
         {
             transform.Translate(0f, 0f, 1f * Time.deltaTime);
         }
 
         if (Camera.transform.position.z > Player.transform.position.z + -3) //move back
         {
             transform.Translate(0f, 0f, -1f * Time.deltaTime);
         }
 
         if (Camera.transform.position.y < Player.transform.position.y + 1) //move up
         {
             transform.Translate(0f, 1f * Time.deltaTime, 0f);
         }
 
         if (Camera.transform.position.y > Player.transform.position.y + 1) //move down
         {
             transform.Translate(0f, -1f * Time.deltaTime, 0f);
         }
     }
 }
 

This is what I wanted

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
avatar image
0

Answer by $$anonymous$$ · Jun 04, 2016 at 05:11 PM

to rotate:

  transformObject.eulerAngles = Vector3(x,y,z) //x,y,z or Vector3 variable

to move:

 transformObject.translate(x,y,z); //x,y,z or Vector3 variable

@Eudaimonium has correct answer too :) but i prefer translate :D

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

56 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

My camera is moving away from the object it's rotating around, how do I fix this? 0 Answers

Perfectly Syncing the rotation of two objects 0 Answers

transform.lookat not working? 0 Answers

Enemy not facing player when enter rotation orbit 0 Answers

Car Controls without physics. 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