void SpawnOnGround() { C_activeState = C_moveGround; //will store info of successful ray cast RaycastHit hitInfo; //terrain should have mesh collider and be on custom terrain //layer so we don't hit other objects with our raycast LayerMask layer = 1 << LayerMask.NameToLayer("Terrain"); Vector3 worldterrainDetect; Vector3 worldterrainDir; worldterrainDetect = transform.position; worldterrainDir = Vector3.down; if (Physics.Raycast(worldterrainDetect, worldterrainDir, out hitInfo, 1000f, layer)) { transform.position = hitInfo.point + Vector3.up * MCglobals.f_desiredHeight; C_activeState = C_moveGround; } else { C_activeState = C_moveJump; } }
protected void DoStateChange(MoveStateBase change) { if (MC.C_activeState != change) { change.SetupState(); MC.C_activeState = change; Debug.Log("Movestate changed to " + change.GetType()); } }