Where it says “here”. it actually prints it, meaning the condition is met, but the velocity is not changed. why?
// Jump controls
Debug.Log (rigidbody.velocity);
if (Input.GetKey (KeyCode.Space) && Jumping == false && transform.position.y - transform.lossyScale.y / 2 < Terrain.activeTerrain.SampleHeight (transform.position) + 1)
{
Jumping = true;
}
if (transform.position.y - transform.lossyScale.y / 2 >= Terrain.activeTerrain.SampleHeight (transform.position) + JumpHeight * 10)
{
Jumping = false;
}
if (Jumping == true)
{
rigidbody.velocity = new Vector3 (0, (JumpSpeed / ((Terrain.activeTerrain.SampleHeight (transform.position)) + JumpHeight * 10 - transform.position.y - transform.lossyScale.y / 2) * 16), 0);
}
if (Jumping == false)
{
if (transform.position.y - transform.lossyScale.y / 2 > Terrain.activeTerrain.SampleHeight (transform.position) + 1)
{
Debug.Log ("Here");
rigidbody.velocity = new Vector3 (0, -(JumpSpeed / ((Terrain.activeTerrain.SampleHeight (transform.position)) + JumpHeight * 10 - transform.position.y - transform.lossyScale.y / 2) * 16), 0);
} else {
rigidbody.velocity = new Vector3 (0, 0, 0);
}
}
i dont but i like keeping consistent in the pattern of my coding, ocd :{
I have it working now, but when he falls he sometimes shoots through the floor and snaps back up. heres my code
if (Input.GetKey (KeyCode.Space) && PlayerFoot < TerrainHeight + 1)
{
Jumping = true;
}
if (Jumping == true)
{
if (PlayerFoot < TerrainHeight + JumpHeight * 10 - 1)
{
PlayerFootSet = PlayerFoot;
if (PlayerFoot < (TerrainHeight + JumpHeight * 10) / 4 * 3)
{
rigidbody.velocity = new Vector3 (0, (JumpSpeed / (TerrainHeight + JumpHeight * 10 - PlayerFoot)) * 32, 0);
} else {
rigidbody.velocity = new Vector3 (0, (JumpSpeed / (TerrainHeight + JumpHeight * 10 - PlayerFoot)) * 24, 0);
}
} else {
Jumping = false;
}
}
if (Input.GetKeyUp (KeyCode.Space))
{
Jumping = false;
}
if (Jumping == false && PlayerFoot > TerrainHeight + 1)
{
if (PlayerFoot < (TerrainHeight + JumpHeight * 10) / 4 * 3)
{
rigidbody.velocity = new Vector3 (0, -(JumpSpeed / (TerrainHeight + JumpHeight * 10 - PlayerFootSet)) * 32, 0);
} else {
rigidbody.velocity = new Vector3 (0, -(JumpSpeed / (TerrainHeight + JumpHeight * 10 - PlayerFootSet)) * 24, 0);
}
}
if (Jumping == false && PlayerFoot <= TerrainHeight + 1)
{
rigidbody.velocity = new Vector3 (0, 0, 0);
}
What what happening is he was going slightly over the jump height because i used if <=, so i made it < and made the -1 so he would never exceed