Hi, i am trying to build a game in which the player touches the coin, the coin has to translate at 45 degrees in an arc shape like the coins in temple run game which moves when the player touches it. Here i am not using colliders for both coins and player. i am not getting how to make it as i am a beginner. I am using c# script for this. Please help…
I guess you just want your coin to rotate:
float speed = 20;
transform.Rotate(Vector3.up * Time.deltaTime*speed);
I do not get the 45degrees thing as they rotate full circle in Temple Run.
And for the record, rotating means moving a set of point by an angle around a unique point.
Translating means moving a set of point by a unique vector so that all the point have been moving the same distance in the same direction.
Those two are done with different types of matrices. The third type is scaling (-oh like the third member of the Transform component? -yes.)
You can also combine all of them at the same time though and make one complicated matrix.
EDIT: Ok I think I get what you want:
float distance = 2f;
float angle = 45f;
// This gets the vector from the forward of your object
// and rotates it 45 degrees (clockwise) around the world up axis
// That considers your object up is aligned with the world up.
Vector3 newVector = Quaternion.AngleAxis(angle, Vector3.up) * transform.forward;
// Make the vector of length/magnitude 1
newVector.Normalize();
// Extend the vector by a distance
newVector *= distance;
//Position the object
transform.position = newVector;
newVector is then a vector starting from your object pointing to the right and forward at 45degreesof your object with a length of 2units. The object is then positioned at the end of that vector.
If you need to get your object to the left simply give a negative angle or a 315degrees.