- Home /
Rotate against player when hit
Hi there!
I'm working on a game on where the player is going to be able to chop down trees. Trees have health, and the player must hit them until the tree health is below 0, then it would just destroy.
The problem is, I'm trying to give a nice feeling when hitting the trees, my idea is to make the tree rotate against the direction the player is on, so it definitely feels like you punched the tree.
Here's an image about what I'm trying to accomplish:
And here's what I tried:
Quaternion.Euler(transform.eulerAngles - player.position * 5);
With what I tried, it actually rotates, but it's not against the player's position, it just rotates against some position I don't understand..
Where am I wrong? I've been for hours with this and don't seem to understand what's wrong.
PS: The script is on the tree, ofcourse.
Answer by MidgardDev · Feb 14, 2015 at 02:40 AM
After taking a deep breath I could see the mess I was doing, so I've got the solution.
Here's what I did:
Quaternion.FromToRotation(Vector3.up, player.forward * 5);
Sorry for creating the thread!
Your answer
Follow this Question
Related Questions
Camera rotation around player while following. 6 Answers
How would I rotate a position vector to get a new position vector. 1 Answer
How to keep position on input.get axis even when it is pressed twice? 1 Answer
move to a position not being looked at 1 Answer
How to rotate/scale a prefab instance from the GUI? 2 Answers