- Home /
Player Movement - Orbiting and changing location of orbit.
Hi people,
I'm relatively new to Unity and coding in general. I've recently started a project where you are a ship protecting planets, however instead of freely flying around in space you are stuck orbiting around the planet that you're protecting (this game is somewhat inspired by Space Invaders where you are defending a "point".
So far I have very basic orbit movement where the player's "ship" will rotate around a centre "point", however it's not really what I want it to do in the long run.
I intend on having the ability to "teleport" between different planets on the fly, at which point dependent on the angle you're currently rotated at on one planet, you would end up on the other planet at the same angle, but at a different distance from the centre of the planet dependent on the size of the planet.
For anyone interested here is my current veeeery basic movement code:
public GameObject currentOrbit;
public float speed;
private void Update()
{
if (Input.GetKey(KeyCode.D))
{
OrbitRight();
}
if (Input.GetKey(KeyCode.A))
{
OrbitLeft();
}
}
void OrbitRight()
{
transform.RotateAround(currentOrbit.transform.position, Vector3.back, speed * Time.deltaTime);
}
void OrbitLeft()
{
transform.RotateAround(currentOrbit.transform.position, Vector3.forward, speed * Time.deltaTime);
}
I would really appreciate any help at all.
Thanks in advanced.