Gravity problems..
Hey guys, newbie to game dev here. I have a little experience with c# and I am using it for the game I am currently trying to develop. So my problem is, i've written a eight direction character controller with the help of some tutorials on Youtube. Everything works great when I have it applied to an avatar on a flat plane with standard gravity applied to it. But when I try and use it in a scene containg a sphere using faux gravity it locks up. Being a newbie to this im sure the answer is obvious and I just lack the knowledge. If anyone could post a link to a tutorial that might help or take a look at the code included i'd really appreciate it.
public class FauxMarioControls : MonoBehaviour {
public float velocity = 5;
public float turnSpeed = 10;
Vector2 input;
float angle;
Quaternion targetRotation;
Transform cam;
Animator anim;
void Start()
{
cam = Camera.main.transform;
anim = GetComponent<Animator>();
}
void Update()
{
GetInput();
if (Mathf.Abs(input.x) < 1 && Mathf.Abs(input.y) < 1) return;
CalculateDirection();
Rotate();
Move();
}
void GetInput()
{
input.x = Input.GetAxisRaw("Horizontal");
input.y = Input.GetAxisRaw("Vertical");
anim.SetFloat("BlendX", input.x);
anim.SetFloat("BlendY", input.y);
}
void CalculateDirection()
{
angle = Mathf.Atan2(input.x, input.y);
angle = Mathf.Rad2Deg * angle;
angle += cam.eulerAngles.y;
}
void Rotate()
{
targetRotation = Quaternion.Euler(0, angle, 0);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, turnSpeed * Time.deltaTime);
}
void Move()
{
transform.position += transform.forward * velocity * Time.deltaTime;
}
}
Your answer
Follow this Question
Related Questions
Game crashes on iPhone 11 0 Answers
Getting trouble in migrating the Unity IAP old version to new version of IAP in existing project 0 Answers
Particles appearing behind background image 0 Answers
how do i remember a just instantiated prefab as a variable gameobject? 1 Answer
Game Scene lags while starting 0 Answers