Well, changing everything to 50 on the Y did not make a difference. I seriously can’t see what I am overlooking. Here is the code attached to the player and I hope one of you can see it easily:
public class player : MonoBehaviour
{
public float Gravity = 21f; //downward force 21f
public float TerminalVelocity = 20f; //max downward speed
public float JumpSpeed = 20f; //20f
public float MoveSpeed = 20f;
public float ThrowDistance = 2f;
public float distanceFromBody;
public int currentHealth = 100;
public bool testCollide = false;
public bool finishLevel = false;
public bool isAlive = true;
public bool playerTakeDamage = true;
public bool trainerAccess = false;
public int jumpInt = 0;
public int duckAttackDamage;
public int testMove = 0;
public GUISkin mySkin;
//public Thread runJumpBack = new Thread(new ThreadStart(jumpBack));
//Ability variables
public int trainingPoints = 0;
public bool throwingAbility = false;
public int throwingObjects = 0;
public bool fartAbility = false;
public int gasLevel = 0;
public bool doubleJump = false;
Stopwatch s = new Stopwatch();
public Vector3 MoveVector {get; set;}
public float VerticalVelocity {get; set;}
public Vector3 throwVector {get; set;}
public CharacterController CharacterController;
public GameObject duckPlayer;
public GameObject fartHolder;
public GameObject projectileHolder;
public string trainerConversation = "Well, looks like you have found away to not get yourself killed.....one of the lucky few.";
void OnGUI()
{
GUI.skin = mySkin;
//GUI.backgroundColor = Color.black;
if(isAlive)
{
GUI.Label (new Rect (25, 25, 100, 30), "Life");
GUI.Box(new Rect(25,45,Screen.width/4,Screen.height/25),"");
GUI.Box(new Rect(25,45,Screen.width/4,Screen.height/25),currentHealth.ToString());
GUI.Box(new Rect(25,85,Screen.width/4,Screen.height/25),distanceFromBody.ToString());
if(finishLevel)
{
GUI.Box(new Rect(Screen.width/2,Screen.height/2,Screen.width/4,Screen.height/5),"Level Complete!!");
}
else if(trainerAccess)
{
GUI.Window(0, new Rect((Screen.width/2)-150, (Screen.height/2)-75, 300, 250), ShowGUI, "Trainer");
//GUI.Box (new Rect (Screen.width/2, Screen.height/2, 100, 30), "Trainer");
}
}
else
{
GUI.Box(new Rect(Screen.width/2,Screen.height/2,Screen.width/4,Screen.height/5),"You died, BITCH!!!");
//StartCoroutine(waitMethod());
}
}
// Use this for initialization
void Awake () {
//DontDestroyOnLoad(this);
//DontDestroyOnLoad(CharacterController);
//this.transform.localPosition.Set(-23,1,0);
CharacterController = gameObject.GetComponent("CharacterController") as CharacterController;
//fartHolder = Instantiate(Resources.Load("Weapons/fartHolder")) as GameObject;
//fartHolder.active = false;
//duckPlayer = gameObject.GetComponent("mainCharacter");
if(finishLevel)
{
//Instantiate(this);
this.transform.localPosition.Set(-23,51,0);
finishLevel = false;
}
}
// Update is called once per frame
void Update ()
{
deathWatch();
if(isAlive)
{
checkMovement();
HandleActionInput();
jumpBack();
processMovement();
}
}
void checkMovement(){
//move l/r
//var deadZone = 0.1f;
VerticalVelocity = MoveVector.y;
MoveVector = Vector3.zero;
if(Input.GetKey(KeyCode.D)){
MoveVector += new Vector3(10f * Time.deltaTime,0,0);
}
else if(Input.GetKey(KeyCode.A)){
MoveVector -= new Vector3(10f * Time.deltaTime,0,0);
}
//jump
}
void HandleActionInput(){
if(Input.GetKeyDown(KeyCode.Space)){
jump();
}
if(Input.GetKeyDown(KeyCode.F))
{
fartHolder = Instantiate(Resources.Load("Weapons/fartHolder")) as GameObject;
fartHolder.transform.position = new Vector3(this.transform.localPosition.x,11,0);
Destroy(fartHolder,6);
}
if(Input.GetKeyDown(KeyCode.R))
{
distanceFromBody = 0f;
distanceFromBody = this.transform.position.y; //using this to just show the Y value
projectileHolder = Instantiate(Resources.Load("Weapons/throwingWeapon")) as GameObject;
projectileHolder.transform.position = new Vector3(this.transform.localPosition.x,this.transform.position.y,0);
//projectileHolder.transform.position = transform.position + Vector3.up;
//projectileHolder.rigidbody.AddForce(10f, 0, 0);
//Destroy(projectileHolder,8);
}
}
// void throwObject()
// {
// int x = 0;
// throwVector = new Vector3(-20,1,0);
// //projectileHolder.transform.position = Vector3.Lerp(projectileHolder.transform.position,throwVector,0.1f);
// //projectileHolder.transform.Translate(throwVector, ThrowDistance);
// while(x<50)
// {
// projectileHolder.transform.Translate(Time.deltaTime,0,0);
// //Thread.Sleep(200);
// x++;
// }
// }
void processMovement(){
//transform moveVector into world-space relative to character rotation
MoveVector = transform.TransformDirection(MoveVector);
//normalize moveVector if magnitude > 1
if(MoveVector.magnitude > 1){
MoveVector = Vector3.Normalize(MoveVector);
}
//multiply moveVector by moveSpeed
MoveVector *= MoveSpeed;
//reapply vertical velocity to moveVector.y
MoveVector = new Vector3(MoveVector.x, VerticalVelocity, MoveVector.z);
//apply gravity
applyGravity();
//move character in world-space
CharacterController.Move(MoveVector * Time.deltaTime);
}
void applyGravity(){
if(MoveVector.y > -TerminalVelocity){
MoveVector = new Vector3(MoveVector.x, (MoveVector.y-Gravity*Time.deltaTime), MoveVector.z);
}
if(CharacterController.isGrounded MoveVector.y < -1){
MoveVector = new Vector3(MoveVector.x, (-1), MoveVector.z);
}
}
public void jump(){
if(CharacterController.isGrounded){
VerticalVelocity = JumpSpeed;
}
}
void OnCollisionEnter(Collision collision)
{
//testCollide = true;
//currentHealth += 10;
// if(collision.gameObject.tag == "Enemy")
// {
// currentHealth = 100;
// }
}
void OnTriggerEnter(Collider collision)
{
//testCollide = true;
if(collision.gameObject.tag == "Enemy")
{
if(testCollide)
{
}
else
{
testCollide = true;
currentHealth += duckAttackDamage;
}
if(playerTakeDamage)
{
playerTakeDamage = false;
//currentHealth += duckAttackDamage;
//duckAttackDamage = 0;
}
//jumpBack();
}
else if(collision.gameObject.tag == "trainer" trainingPoints > 0)
{
trainerAccess = true;
}
else if(collision.gameObject.tag == "FinishObject")
{
finishLevel = true;
}
//((collision.transform.position.y + .3) < transform.position.y)
//runJumpBack.Start();
}
void jumpBack()
{
if(testCollide)
{
testCollide = false;
//currentHealth += duckAttackDamage;
//duckAttackDamage = 0;
MoveSpeed = 100f;
jump();
for(int i=0;i<8000;i++)
{
MoveVector -= new Vector3(10f * Time.deltaTime,0,0);
}
MoveSpeed = 20f;
}
}
public void adjustPlayerHealth(int adj)
{
duckAttackDamage = adj;
playerTakeDamage = true;
}
void deathWatch()
{
if(currentHealth <= 0)
{
isAlive = false;
Application.LoadLevel("level1");
}
else if(finishLevel)
{
levelLoader();
}
}
void levelLoader()
{
DontDestroyOnLoad(CharacterController);
DontDestroyOnLoad(this);
Application.LoadLevel("level2");
finishLevel = false;
this.transform.position = new Vector3(-23,51,0);
fartHolder = (GameObject)Instantiate(Resources.Load("Weapons\fartHolder"));
//this.transform.localPosition.Set(-23,1,0);
}
IEnumerator waitMethod()
{
yield return new WaitForSeconds(7);
}
void ShowGUI(int windowID)
{
// You may put a label to show a message to the player
GUI.Label(new Rect(10, 40, 300, 200), trainerConversation);
// You may put a button to close the pop up too
if (GUI.Button(new Rect(10, 210, 75, 30), "Done"))
{
trainerAccess = false;
trainerConversation = "Well, looks like you have found away to not get yourself killed.....one of the lucky few.";
// you may put other code to run according to your game too
}
else if (GUI.Button(new Rect(95, 210, 75, 30), "Back"))
{
trainerConversation = "You clicked back.......didn't get it the first time?.....mumble...dipshit.....mumble......";
// you may put other code to run according to your game too
}
else if (GUI.Button(new Rect(180, 210, 75, 30), "Next"))
{
trainerConversation = "May want an array of statements....";
// you may put other code to run according to your game too
}
}
}
Thanks for any input you can give and if any other info is needed, let me know.