- Home /
Playing with the Gravity PROBLEM
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?
It's obviously a problem with the character motor script.
@Benproductions1 Then what do you recommend to do? I do not have a lot of experience with Unity, this is my first game project with this engine, so I don't know what to do. Do you mean that the Character $$anonymous$$otor script could be corrupted or anything like that?
Not corrupted, but not working either... I usually make my own character moving script and I have no idea how the character motor script works, but that is where the problem lies