rotate object towards target rotation slowly unity
C#
/// <summary>
/// Rotate a gameobject to face a direction in 2D space with offet
/// </summary>
/// <param name="target"></param>
/// <param name="RotationSpeed"></param>
/// <param name="offset"></param>
private void RotateGameObject(Vector3 target, float RotationSpeed, float offset)
{
//https://www.youtube.com/watch?v=mKLp-2iseDc
//get the direction of the other object from current object
Vector3 dir = target - transform.position;
//get the angle from current direction facing to desired target
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
//set the angle into a quaternion + sprite offset depending on initial sprite facing direction
Quaternion rotation = Quaternion.Euler(new Vector3(0, 0, angle + offset));
//Roatate current game object to face the target using a slerp function which adds some smoothing to the move
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, RotationSpeed * Time.deltaTime);
}
Also in C#:
- Title
- array c#
- Category
- C#
- Title
- chase object unity
- Category
- C#
- Title
- convert generic to type c#
- Category
- C#
- Title
- c#if
- Category
- C#
- Title
- count the number of notes in a given amount c#
- Category
- C#
- Title
- string to enum c#
- Category
- C#
- Title
- c# get directory part of path
- Category
- C#
- Title
- c# how to exit program
- Category
- C#
- Title
- c# get list of all class fields
- Category
- C#
- Title
- c# mixed multidimensional array
- Category
- C#
- Title
- convert string to boolean c#
- Category
- C#
- Title
- move file from one folder to another c#
- Category
- C#
- Title
- create object in c#
- Category
- C#
- Title
- Unity if object doens't exist
- Category
- C#
- Title
- displayname c#
- Category
- C#
- Title
- unity hide mouse
- Category
- C#
- Title
- c# odd even median
- Category
- C#
- Title
- Instantiate c#
- Category
- C#
- Title
- The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located.
- Category
- C#
- Title
- c# list append
- Category
- C#
- Title
- how to find the type of a object c#
- Category
- C#
- Title
- phone
- Category
- C#
- Title
- c# check if string is all numbers
- Category
- C#
- Title
- how to find the area of a circle
- Category
- C#
- Title
- unity lerp
- Category
- C#
- Title
- c# list to string
- Category
- C#
- Title
- javascript append
- Category
- C#
- Title
- how to convert iformfile to byte array c#
- Category
- C#
- Title
- change textbox location C#
- Category
- C#
- Title
- c# windows forms draw pixel
- Category
- C#
- Title
- create dropdown in datatable c# dynamically
- Category
- C#
- Title
- c# check if type implements interface
- Category
- C#
- Title
- leantween id
- Category
- C#
- Title
- how to make a datatable in c#
- Category
- C#
- Title
- copy a list in c# unity
- Category
- C#
- Title
- c# adding to a list
- Category
- C#
- Title
- how to get array of children transform
- Category
- C#
- Title
- how to a equall to b in c#
- Category
- C#
- Title
- c# httpclient azure function authorization
- Category
- C#
- Title
- c# winform remove button border
- Category
- C#
- Title
- unity how to change the text on a button
- Category
- C#
- Title
- c# how to run external program with args
- Category
- C#
- Title
- background color with opacity
- Category
- C#
- Title
- how to destroy a gameobject after some hits in unity 3d
- Category
- C#
- Title
- razor preview
- Category
- C#
- Title
- datatable return column names
- Category
- C#
- Title
- How to get number of months between 2 dates c#
- Category
- C#
- Title
- math class C# exponents
- Category
- C#
- Title
- unity pro version free download
- Category
- C#
- Title
- new command - latex
- Category
- C#
- Title
- what function is called just before the a script is ended c#
- Category
- C#
- Title
- how to locate a specific element in a list c#
- Category
- C#
- Title
- how to reference the position of a game object unity
- Category
- C#
- Title
- unity collider2d contains point
- Category
- C#
- Title
- no overload for 'useItemOnSceneLoad' matches delegate 'UnityAction<Scene, LoadSceneMode>'
- Category
- C#
- Title
- how to do a messagebox in c#
- Category
- C#
- Title
- .net core get image from url
- Category
- C#
- Title
- how do I attach a player with a navMeshAgent
- Category
- C#
- Title
- unity t-flip flop
- Category
- C#
- Title
- wpf label text in center
- Category
- C#
- Title
- c# LCP
- Category
- C#
- Title
- set int to null c#
- Category
- C#
- Title
- c# get time
- Category
- C#
- Title
- how to create a list in c# unity
- Category
- C#
- Title
- or in unity c#
- Category
- C#
- Title
- unity rotation
- Category
- C#
- Title
- unity custom update
- Category
- C#
- Title
- snippet to create constructor in asp.net c#
- Category
- C#
- Title
- create line in unity
- Category
- C#
- Title
- c# generate random number
- Category
- C#
- Title
- C# downloadstirng download old
- Category
- C#
- Title
- c# get every point in a line in matrix
- Category
- C#
- Title
- creating a c# class
- Category
- C#
- Title
- C# how to get public key for InternalsVisibleTo
- Category
- C#
- Title
- 5 second timer in c#
- Category
- C#
- Title
- import regex c#
- Category
- C#
- Title
- c# find element in list of list
- Category
- C#
- Title
- ping with c#
- Category
- C#
- Title
- Assets\playermove.cs(30,37): error CS1003: Syntax error, ',' expected
- Category
- C#
- Title
- Assets/Scripts/Snake.cs(187,10): error CS0029: Cannot implicitly convert type `UnityEngine.Vector2Int' to `System.Collections.Generic.List<UnityEngine.Vector2Int>'
- Category
- C#
- Title
- find gameobject with tag
- Category
- C#
- Title
- wpf use enum description
- Category
- C#
- Title
- void start
- Category
- C#
- Title
- functions unity
- Category
- C#
- Title
- c# convert dictionary to anonymous object
- Category
- C#
- Title
- top down movement unity
- Category
- C#
- Title
- reload current scene unity
- Category
- C#
- Title
- isInstanceOf nunit
- Category
- C#
- Title
- wpf datatrigger enum binding
- Category
- C#
- Title
- unity ai wander script
- Category
- C#
- Title
- how to get odd saturday in a month in c#
- Category
- C#
- Title
- newtonsoft create dynamic object
- Category
- C#
- Title
- 2d object look at object
- Category
- C#
- Title
- how to do cmd command c#
- Category
- C#
- Title
- how to create public variable in c#
- Category
- C#
- Title
- c# get enum in list
- Category
- C#
- Title
- how to deactivate objects through scripts in unity
- Category
- C#
- Title
- unity how to change rotation
- Category
- C#
- Title
- c# list string return concatenate
- Category
- C#
- Title
- c# query string builder
- Category
- C#