(Note: I am very new here and I don’t know all the codings)
I want to know how can I make my character’s body rotate when my first person camera touches and angle. For example, if the camera reaches 15 degres, then the character should start rotating. It’s like minecraft when the player is in third person, he can see that the character’s body rotates along with the camera when it reaches a limit.
If I’m not mistaken, it might be some sort of a coding with IEnumerator, but I don’t know what to add next in order to work like I want to.
I successfuly made the body rotate with the FP camera, but it rotates too perfect.
Here is what I use:
using UnityEngine;
using System.Collections;
public class BodyRotator : MonoBehaviour
{
public float speedH = 2.0f;
public float speedV = 2.0f;
// only check on the X-Z plane:
Vector3 cameraDirection = new Vector3(camera.forward.x, 0f, camera.forward.z);
Vector3 playerDirection = new Vector3(player.forward.x, 0f, player.forward.z);
if(Vector3.Angle(cameraDirection, playerDirection) > 15f)
{
body.rotation = Quaternion.RotateTowards(body.rotation, camera.rotation, however fast you want);
}
And where exactly should I put this? it gives me an error at the body.rotation. And even if I add the object body, it tells me that " ‘object’ does not contain a definition for ‘rotation’ and no extension method ‘rotation’ accepting a first argument of type ‘rotation’ could be found (are you missing a using directive or an assembly reference?)"
Like I said, I am new in unity, and I don’t know so many things about it.
The code does not work. Even if I change body to transform, it still gives me an error that unity can’t convert from “this” to “this”
What code am I supposed to use and WHERE is supposed to be?
I just said in the first post of this topic. I want my character’s body to rotate when the neck that has a camera inside touches a certain angle. For example, if the neck reaches 15 degrees, then the body should start rotating. It’s how you rotate the character from minecraft.
Oh wait, I didn’t notice how you modified the 15f in the angle check to maxDegreesDelta. If nothing else, that should be back to 15f in that portion. See if that fixes it.
Confirmed, the script was still in the whole character and one in the bones, I tried removing from the bones and let it remain in the character and nothing bad happened. The script is doing his job perfectly. Thank you so much ;D
I can now move on to add some other features.
Hmmmm, one thing I noticed. Yes, the character does rotate with the camera, but the camera kinda shakes when the body is rotating. If I set the speed super low, it won’t shake anymore but the rotation is too slow, but if I set the speed a bit faster like any other first person game, it shakes the camera very badly. What is causing this? I think the code is missing something that might fix this problem. But what?
What I was trying to say it was that when I stop rotation the camera and wait for the body finish it’s rotation, then the camera will shake until I’m not rotating the character anymore.
How can I prevent this?