unity how to make a gameobject slowly look at a position
Java
Quaternion lookAtSlowly(Transform t , Vector3 target , float speed){
//(t) is the gameobject transform
//(target) is the location that (t) is going to look at
//speed is the quickness of the rotation
Vector3 relativePos = target - t.position;
Quaternion toRotation = Quaternion.LookRotation(relativePos);
return Quaternion.Lerp(t.rotation, toRotation, speed * Time.deltaTime);
}
void update()
{
transform.rotation = lookAtSlowly(transform , new Vector3(0,0,0) , 1);
}
/// <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 Java:
- Title
- list java oracle
- Category
- Java
- Title
- spring framework iterate
- Category
- Java
- Title
- boolean checkbox swing
- Category
- Java
- Title
- refrence xml textfield in javafx
- Category
- Java
- Title
- has places api got deprecated???
- Category
- Java
- Title
- java find biggest number in array
- Category
- Java
- Title
- insertion sort doubly linked list java
- Category
- Java
- Title
- java jpa criteriabuilder in xample
- Category
- Java
- Title
- Java nested array hashcode
- Category
- Java
- Title
- how to check if a list is empty java
- Category
- Java
- Title
- java stack methods
- Category
- Java
- Title
- java download file from url to string
- Category
- Java
- Title
- java print syntax
- Category
- Java
- Title
- java 8 hashmap example stackoverflow
- Category
- Java
- Title
- convert string into unicode java
- Category
- Java
- Title
- how to push an element in hashset java
- Category
- Java
- Title
- java string regexp replace
- Category
- Java
- Title
- android switch on change
- Category
- Java
- Title
- covariant type in java
- Category
- Java
- Title
- how to make int array java android
- Category
- Java
- Title
- android round double to 2 decimal
- Category
- Java
- Title
- how to echo java_home in windows cmd
- Category
- Java
- Title
- inheritance setter and getter in java
- Category
- Java
- Title
- loop collection android
- Category
- Java
- Title
- string length in java
- Category
- Java
- Title
- java resource file
- Category
- Java
- Title
- online money transfer andhra bank
- Category
- Java
- Title
- Don't use a line-beased input after a token-based input.
- Category
- Java
- Title
- function in java
- Category
- Java
- Title
- write an infinite loop java
- Category
- Java
- Title
- convert string to localdatetime
- Category
- Java
- Title
- java windowbuilder full screen
- Category
- Java
- Title
- working with buttons in applet java
- Category
- Java
- Title
- junit meaning in java
- Category
- Java
- Title
- how to break from a loop in java
- Category
- Java
- Title
- goodbye java
- Category
- Java
- Title
- java swing button on click
- Category
- Java
- Title
- how to add jar in maven java application in netbeans
- Category
- Java
- Title
- how to write a merge sort array method ni java
- Category
- Java
- Title
- java array to arraylist
- Category
- Java
- Title
- java script dynamic varibale creation
- Category
- Java
- Title
- numberformatexception
- Category
- Java
- Title
- jbutton open jframe java
- Category
- Java
- Title
- android java how to stop users fromgoing back too much
- Category
- Java
- Title
- else statement java
- Category
- Java
- Title
- java binary exponentiation
- Category
- Java
- Title
- array of objects in java
- Category
- Java
- Title
- generate all prime number less than n java (fastest method)
- Category
- Java
- Title
- java implement interface
- Category
- Java
- Title
- padding a string with 0 in java
- Category
- Java
- Title
- java load image
- Category
- Java
- Title
- nullpointer extension
- Category
- Java
- Title
- error message pushes button down
- Category
- Java
- Title
- java get an int from a char
- Category
- Java
- Title
- instantiate optinal java 8
- Category
- Java
- Title
- switch java 11
- Category
- Java
- Title
- how to add a keylistener to a jframe
- Category
- Java
- Title
- para que sirve getcontentpane en java
- Category
- Java
- Title
- how to make generic arraylist in java
- Category
- Java
- Title
- array methods in java
- Category
- Java
- Title
- java hashmap syntax
- Category
- Java
- Title
- fastapi list query parameter
- Category
- Java
- Title
- java mysql springboot jpa stackoverflow
- Category
- Java
- Title
- java initialize float to zero
- Category
- Java
- Title
- how to break two loop in java
- Category
- Java
- Title
- what is a float java
- Category
- Java
- Title
- palindrome function java
- Category
- Java
- Title
- Removing DOM nodes when traversing a NodeList
- Category
- Java
- Title
- java mouseevent
- Category
- Java
- Title
- java define main function
- Category
- Java
- Title
- Category
- Java
- Title
- selection sort in java
- Category
- Java
- Title
- alfred workflow
- Category
- Java
- Title
- convert java list to array
- Category
- Java
- Title
- spigot deal damage
- Category
- Java
- Title
- error attribute fabattached not found
- Category
- Java
- Title
- java string to char array
- Category
- Java
- Title
- java create new object
- Category
- Java
- Title
- how to compare strings java
- Category
- Java
- Title
- how to make one java class inherit from another
- Category
- Java
- Title
- check if a string is a substring of another string java
- Category
- Java
- Title
- abstract class java constructor
- Category
- Java
- Title
- count occurrences of character in string java 8
- Category
- Java
- Title
- how do I change the opacity of a JButton
- Category
- Java
- Title
- Common GIt Commands
- Category
- Java
- Title
- declare bufferedreader java
- Category
- Java
- Title
- D/NetworkSecurityConfig: No Network Security Config specified, using platform default
- Category
- Java
- Title
- java swing change label icon
- Category
- Java
- Title
- two dimensional array in java example program
- Category
- Java
- Title
- java shortest if else statement
- Category
- Java
- Title
- java 8 string to localdate
- Category
- Java
- Title
- java interface
- Category
- Java
- Title
- find frequency of each word in a string in java
- Category
- Java
- Title
- bukkit java connect player to another server in bungeecord
- Category
- Java
- Title
- how to make a list java
- Category
- Java
- Title
- java instantiate collection with values
- Category
- Java
- Title
- java how to read a text file
- Category
- Java
- Title
- java scanner next()
- Category
- Java
- Title
- java regex replace all characters before
- Category
- Java
- Title
- find numbers in a string java
- Category
- Java