dear unity community,
I make a game, where the player stands on a planet and automatically walks around it. The player always rotates around the world in the same direction. Always around the vector3.right-axis of the planet. There is also an enemy, who walks on the opposite side of the planet. Like the player, the enemy also rotates around the planet in the same direktion as the player does (see picture 1).
The player can fly away from the planet only in the transform.up-direction and gravity pulls him down to earth.
Here comes my problem: When i jump resp. fly away and apply force to the rigidbody, the rotation movement of my player slightly decreases and the enemy get closer to the player (see picture 2). For my game, it’s essential, that the player rotates alway at the same speed around the planet whatever altitude he has. For the rotation around the planet, i use RotateAround. As RotateAround rotates the player by angle degrees around the planet, the altitude should not affect the rotation speed. So i guess, that the applied up-force affect the rotationspeed somehow?
After a lot of web-searching, i am still clueless. I hope, there is some smart programmer out there, who can help me.
Thank you in advance!
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerMovement : MonoBehaviour
{
public float gravity = -10;
public float jumpSpeed = 15;
public GameObject planet;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
// player Rotation
Vector3 targetDir = (transform.position - planet.transform.position).normalized;
Vector3 bodyUp = transform.up;
transform.rotation = Quaternion.FromToRotation(bodyUp, targetDir) * transform.rotation;
// RotateAround planet (Movement)
transform.RotateAround(planet.transform.position, Vector3.right, 60 * Time.deltaTime);
}
private void FixedUpdate()
{
// jump
if (Input.GetButton("Jump"))
{
GetComponent<Rigidbody>().velocity += transform.up * jumpSpeed * Time.deltaTime; //transform.up
}
// Applying gravity to the controller
GetComponent<Rigidbody>().velocity += transform.up * gravity * Time.deltaTime; // transform.up
}
}