Skip to content
Cuelogic
  • Services
        • Product Engineering
          • Product Development
          • UX Consulting
          • Application Development
          • Application Modernization
          • Quality Assurance Services
        • Cloud Engineering
          • Cloud Services
          • DevOps Services
          • Cloud Migration
          • Cloud Optimization
          • Cloud Computing Services
        • Data & Machine Learning
          • Big Data Services
          • AI Consulting
        • Internet of Things
          • IoT Consulting
          • IoT Application Development
        • Innovation Lab as a Service
        • Cybersecurity Services
        • Healthcare IT Services
  • Company
    • About
    • Culture
    • Current Openings
  • Insights
  • Tell Us Your Project
Tell Us Your Project  ❯
Product Development

How to rotate object in unity3d using Quaternion

2 Mins Read

Following tutorial will guide you how to rotate an object using Quaternion.

  1. I assume you might be aware of basics about unity.
  2. There are different ways for rotating object’s, For example :: rotation using rigidbody, rotation using Quaternion etc .
  3. Choosing the technique for rotating an object depends on the type of object, By “ Type of object ” i mean weather the object has a rigidbody component, character controller or nothing attached to it.
  4. Following technique of rotation is best suited only for  those object which do not have any of the above component.
  5. If  you are using rigidbody component on object then refer following
    link :: How to rotate object in unity3d using Rigidbody
  6. Create a sample  project and add a plane to the scene along with  a cube(TargetObject)  towards which we have rotate our rotationObject(player just to differentiate between two objects).
  7. Now we will add rotation script to object. (QuaternionRotation.cs) using UnityEngine; using System.Collections; public class QuaternionRotation : MonoBehaviour { float rotationSpeed=0.5f ;// This Must be less than 1 and greater than 0 GameObject targetObject=null; // Use this for initialization void Start () { // get target object tobe rotated at targetObject=GameObject.FindGameObjectWithTag("TargetObject") as GameObject; } // Update is called once per frame void Update () { if(targetObject==null){ Debug.Log("[ERROR] => Traget object is null , Can't Rotate"); return; } // get position of target object Vector3 targetPosition=targetObject.transform.position; // calculate rotation to be done Quaternion targetRotation = Quaternion.LookRotation(targetPosition - transform.position); //NOTE :: If you don't want rotation along any axis you can set it to zero is as :- // Setting Rotation along z axis to zero targetRotation.z=0; // Setting Rotation along x axis to zero targetRotation.x=0; // Apply rotation transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime); } }
  8. Now run the scene , And you can see Player object rotating to target object.

Note :-

  1. If you have added rigidybody to rotationObject (player) then you must rotate object using physics (Force,Torque).
  2. Rotation using Quaternion must only be used on object which do not have rigidbody.

Tags
Quaternion Rotation unity3d
Share This Blog
Share on facebook
Share on twitter
Share on linkedin

Leave a Reply Cancel reply

People Also Read

DevOps
What is Infrastructure as Code and How Can You Leverage It?
8 Mins Read
Quality Engineering
Cypress vs. Selenium: Which is the Superior Testing Tool?
7 Mins Read
Product Development
Micro Frontend Deep Dive – Top 10 Frameworks To Know About
10 Mins Read

Other Categories

case study
Case Studies
e book
E-Book
video
Webinars
Subscribe to our Blog
Subscribe to our newsletter to receive the latest thought leadership by Cuelogic experts, delivered straight to your inbox!
Services
Product Engineering
  • Product Development
  • UX Consulting
  • Application Development
  • Application Modernization
  • Quality Assurance
Menu
  • Product Development
  • UX Consulting
  • Application Development
  • Application Modernization
  • Quality Assurance
Data & Machine Learning
  • Big Data Services
  • AI Consulting
Menu
  • Big Data Services
  • AI Consulting
Innovation Lab as a Service
Cybersecurity Services
Healthcare IT Solutions
Cloud Engineering
  • Cloud Services
  • DevOps Services
  • Cloud Migration
  • Cloud Optimization
  • Cloud Computing Services
Menu
  • Cloud Services
  • DevOps Services
  • Cloud Migration
  • Cloud Optimization
  • Cloud Computing Services
Internet of Things
  • IoT Consulting
  • IoT App Development
Menu
  • IoT Consulting
  • IoT App Development
Company
  • About
  • Culture
  • Current Openings
Menu
  • About
  • Culture
  • Current Openings
We are Global
India  |  USA  | Australia
We are Social
Facebook
Twitter
Linkedin
Youtube
Subscribe to our Newsletter
cuelogic

We are Hiring!

Blogs
  • What is Infrastructure as Code and How Can You Leverage It?
  • Cypress vs. Selenium: Which is the Superior Testing Tool?
  • Micro Frontend Deep Dive – Top 10 Frameworks To Know About
  • Micro Frontends – Revolutionizing Front-end Development with Microservices
  • Decoding Pipeline as Code (With Jenkins)
  • DevOps Metrics : 15 KPIs that Boost Results & RoI
Menu
  • What is Infrastructure as Code and How Can You Leverage It?
  • Cypress vs. Selenium: Which is the Superior Testing Tool?
  • Micro Frontend Deep Dive – Top 10 Frameworks To Know About
  • Micro Frontends – Revolutionizing Front-end Development with Microservices
  • Decoding Pipeline as Code (With Jenkins)
  • DevOps Metrics : 15 KPIs that Boost Results & RoI
cuelogic

We are Hiring!

Blogs
  • What is Infrastructure as Code and How Can You Leverage It?
  • Cypress vs. Selenium: Which is the Superior Testing Tool?
  • Micro Frontend Deep Dive – Top 10 Frameworks To Know About
  • Micro Frontends – Revolutionizing Front-end Development with Microservices
  • Decoding Pipeline as Code (With Jenkins)
  • DevOps Metrics : 15 KPIs that Boost Results & RoI
Menu
  • What is Infrastructure as Code and How Can You Leverage It?
  • Cypress vs. Selenium: Which is the Superior Testing Tool?
  • Micro Frontend Deep Dive – Top 10 Frameworks To Know About
  • Micro Frontends – Revolutionizing Front-end Development with Microservices
  • Decoding Pipeline as Code (With Jenkins)
  • DevOps Metrics : 15 KPIs that Boost Results & RoI
We are Global
India  |  USA  | Australia
We are Social
Facebook
Twitter
Linkedin
Youtube
Subscribe Newsletter
Services
Product Engineering

Product Development

UX Consulting

Application Development

Application Modernization

Quality Assurance Services

Cloud Engineering

Cloud Services

DevOps Services

Cloud Migration

Cloud Optimization

Cloud Computing Services

Data & Machine Learning

Big Data Services

AI Consulting

Internet of Things

IoT Consulting

IoT Application Services

Innovation Lab As A Service
Cybersecurity Services
Healthcare IT Services
Company

About

Culture

Current Openings

Insights
Privacy Policy  
All Rights Reserved @ Cuelogic 2021

Close