Hi everyone,
I want to make a “PlayerManager” script that handles things like death falls, respawns, scores, etc., and I’ve done this before in Unity 3 utilizing the CharacterController based off of a script posted here, but now it doesn’t seem to work in Unity 4. Here’s my version of that same script:
#pragma strict
var fallDistance: double = 3;
var deathFall: double = -15;
var falling: boolean = false;
var lastY: float;
private var character: CharacterController;
function Start()
{
character = GetComponent(CharacterController);
lastY = transform.position.y;
}
function Update()
{
if (character.isGrounded == false)
{
falling = true;
}
if (character.isGrounded == true)
{
falling = false;
lastY = transform.position.y;
}
if (falling)
{
var fall: double = lastY - transform.position.y;
if (fall > fallDistance)
{
fall = 0.0;
falling = false;
Debug.Log("OUCH!");
}
}
}
The problem I am having is that the boolean “falling” flashes between states while the game is running - it’s like there’s something wrong in the CharacterController class in which it’s updating between both states, even while the player is perfectly grounded! As a direct result, sometimes the player will fall and the “OUCH” text will not get outputted to the console, even though they fell above the allowed amount. Has anyone else encountered any problems like this, or is there something I’m doing wrong in the script? Although I just tried that original script and it doesn’t work either, so something seems to be afoot! I’m running Windows 8 64bit, if that might have anything to do with it?
If anybody has any solutions I would greatly appreciate it! ![]()
OK, so I posted a [thread][1] about it over in Unity Support, and it seems to be that the Physics engine in Unity isn't updating properly. I've attempted casting a ray to act as a "feeler" for the ground, and it's flashing between states, just like the default isGrounded variable! More information is available in that thread. I'm also now attempting this in Unity 3.5.6f4, just because I'm more comfortable with it. It doesn't matter what version I use, I'm always getting this problem! Very frustrating. [1]: http://forum.unity3d.com/threads/168944-Problems-with-isGrounded-on-Windows-8
– JeremyG