Hi there!
I’m developing a 2.5D platformer game where you can play with the Gravity, when you press SPACE you change the Gravity direction (up or down) and it works well, BUT just if I’m jumping while pressing SPACE, if I press SPACE and then I try to move, my character can’t move anymore and the console gives me the following error:
transform.positionWithLocalOffset assign attempt for ‘PlayerHitbox’ is not valid. Input positionWithLocalOffset is { NaN, NaN, NaN }.
UnityEngine.CharacterController:Move(Vector3)
CharacterMotor:UpdateFunction() (at Assets/Standard Assets/Character Controllers/Sources/Scripts/CharacterMotor.cs:249)
CharacterMotor:FixedUpdate() (at Assets/Standard Assets/Character Controllers/Sources/Scripts/CharacterMotor.cs:367)
Here is my script for change the gravity:
using UnityEngine;
using System.Collections;
public class ChangeGravity : MonoBehaviour
{
public bool gravityInverted;
public float gravityInvertedCount;
public float playerGravity; //NOT USED AT THE MOMENT
public CharacterMotor charMotor;
// Use this for initialization
void Start()
{
charMotor = GetComponent<CharacterMotor>();
gravityInverted = false;
}
// Update is called once per frame
void Update() {
if(Input.GetKeyDown ("space"))
{
gravityInvertedCount++;
gravityInverted = true;
}
if (Input.GetKeyDown("down"))
{
gravityInvertedCount = 2;
}
if (gravityInverted == true)
{
charMotor.movement.gravity = -9.8f;
}
if (gravityInverted == false)
{
charMotor.movement.gravity = 9.8f;
}
if (gravityInvertedCount >= 2)
{
print("Gravity Inverted Count equals 0 again");
gravityInvertedCount = 0;
gravityInverted = false;
}
}
}
Anyone understands what is happening?