I am trying to call this function in a C# script of mine and I am getting an error saying RotateTowards does not exist in current context. Am I missing a using statement or something?
using UnityEngine;
using System.Collections;
using System;
transform.rotation = RotateTowards(transform.rotation, targetRotation, Input.acceleration.x);
doh, Thanks for the help, getting this error now if you know anything about it, if not thanks for the help anyway =)
transform.rotation assign attempt for ‘Constructor’ is not valid. Input rotation is { NaN, NaN, NaN, NaN }.
UnityEngine.Transform:set_rotation(Quaternion)
i tried slerp with the same params and I get no errors, but when I load it onto a device the rotation does nothing. MovePlayer should move back and forth only with Input.accelerator.y, and RotatePlayer should only rotate the player on the Y axis using Input.Accelerator.x. My code starting this problem was
which would rotate the player to turn left and right but would progressively slow down when turning 180 degrees and if you turned exactly behind you it would lock up, would just like to be able to rotate the player around freely. I appreciate the advice john =)
This is my current code
using UnityEngine;
using System.Collections;
using System;
public class tilt : MonoBehaviour {
CharacterController cc;
private Quaternion localRotation;
//float speed = 0.5f;
// Use this for initialization
void Start () {
cc = gameObject.GetComponent<CharacterController>();
localRotation = transform.rotation;
}
// Update is called once per frame
void Update () {
MovePlayer();
RotatePlayer();
}
void MovePlayer() {
//Vector3 dir = Vector3.zero;
if (Input.acceleration.y > -0.6)
{
Vector3 forward = cc.transform.forward;
forward *= 1.7f;
forward.y = 0.0f;
//forward.y = Input.acceleration.y;
cc.Move(forward * Time.deltaTime);
}
if (Input.acceleration.y < -0.8)
{
Vector3 backward = -cc.transform.forward;
backward *= 1.7f;
backward.y = 0.0f;
//forward.y = Input.acceleration.y;
cc.Move(backward * Time.deltaTime);
}
}
void RotatePlayer() {
// find speed based on delta
float curSpeed = Time.deltaTime * 1.5f;
//localRotation.y += Input.acceleration.x * curSpeed;
Quaternion targetRotation = Quaternion.Euler(0, Input.acceleration.x * curSpeed + transform.rotation.eulerAngles.y, 0);
transform.rotation = Quaternion.Slerp(localRotation, targetRotation, Input.acceleration.x);
localRotation.y = transform.rotation.y;
}
}