Hi, I am using scripts from the following source:
http://forum.unity3d.com/threads/8873-Faux-Gravity-making-my-brain-spin…-Help!
This basically sets up a faux gravity system where objects will be pulled towards others as if they had their own central field of gravity. Very useful for achieving similar things to Super Mario Galaxy.
But anyway, my problem is that while I may have a moving character that can be moved forward, back, left and right with the arrow keys along my planet, I would love to be able to rotate the character using the left and right arrow keys, which in turn moves the camera attached to the player object. This would allow for better maneuvering of the character.
So far I have made some progress with it, the following code has been added to the project and calls the gravity script attached to the player, with if statements checking when a jump has occurred, so that the player cannot rotate in mid air. The dilemma is that because the player is moving around a planet, its rotation changes quite a lot; trying to change its rotation with simple script is ineffective as it still rotates it in respect to the game axes.
My code is as follows:
using UnityEngine;
using System.Collections;
public class PlayerTurn : MonoBehaviour
{
public float speed;
public GameObject player;
public PlayerGravityBody gravBody;
public void Update()
{
Vector3 turnAngles = player.transform.rotation.eulerAngles;
if(Input.GetKey ("left") && gravBody.doJump == false)
{
Debug.Log(turnAngles.y);
turnAngles.y -= speed;
}
if(Input.GetKey ("right") && gravBody.doJump == false)
{
Debug.Log(turnAngles.y);
turnAngles.y += speed;
}
}
}
this works okay until you start to pass the equator of the planet and then the rotations seem to reverse.
any help with this would be great ![]()