- Home /
Separate set of movement for when not grounded
Honestly I'm not good at coding, This might be a bit of a weird situation but i essentially want my player character to move in two different ways depending on the conditions. When the player is grounded i want it to move forward normally, And when its not i want it to have something similar to the AddForce effect so that the orientation of the player is changing. Of cource the character can only jump when its grounded. But My game is taking place in space so when the character is in the air and not oriented to the ground i want it to look as though its effected by the space but still moving forward. .Is it possible?
This is the portion of the code I'm currenly using, I have the IsGrounded Raycast on a seperate script. void start() {
rb = GetComponent<Rigidbody>();
info = GetComponent<PlayerInfo>();
}
void FixedUpdate() { if (info.IsGrounded()) {
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3 (horizontal * speed * Time.deltaTime, 0, vertical * speed * Time.deltaTime);
rb.MovePosition(transform.position + movement);
}
if (!info.IsGrounded())
{
if (Input.GetKeyDown(KeyCode.W))
{
rb.AddForce( Vector3.forward);
Debug.Log ("Is this working?");
}
)
Debug is not working... The problem im seeing with this script is that it still only reads the IsGround = true and when not grounded it stops moving all together. I honestly don't understand it much.