Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

Unity transform.LookAt but slowly, not suddenly rotating towards target

Posted on April 26, 2025April 26, 2025 by Habibie

I often use transform.LookAt function in Unity but still I can not understand how to make the object rotation not to quick. I mean, look at this script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LookAtSlowly : MonoBehaviour
{
	
	public GameObject lookAtTarget;
	
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        transform.LookAt(lookAtTarget.transform);
    }
}

This script will rotate the object (with this script attached) towards the transform target (the object that we look at to), but the rotation is too fast. How to make it slower and smooth?

After few tweaks, I finally came out with this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LookAtSlowly : MonoBehaviour
{
	
	public GameObject lookAtTarget;
	public float rotationSpeed = 2.0f; // Adjust this for faster or slower rotation
	
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        Vector3 direction = lookAtTarget.transform.position - transform.position;
		if (direction != Vector3.zero)
		{
			Quaternion targetRotation = Quaternion.LookRotation(direction);
			transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.fixedDeltaTime);
		}
    }
}
Post Views: 333
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
  • Advanced Blinking Marker Script to show objects position in your game canvas
  • Ciihuy Images Merger – Fast & Easy Online Image Combiner
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme