UNITY 5 , Poor Performance in old Project? [HELP!]

Hi guys , I am having a weird problem with Unity 5. I was developing a 3D Platformer game in Unity 4.6 and today when I upgraded to Unity 5 , my character movement is too slow and physics behavior is totally ruined. :frowning:
It seems like there is very small amount of gravity acting on the character , when I play the game , it takes like 15 seconds to reach the ground. Also jumping has gone so weird. I checked my scripts , also checked everything in the inspector , it’s still the same. I can barely move the character. Now I can’t even downgrade and start working on the same project. Please help me , anyone? :frowning:

You have to show something, such that we get a better idea of how your stuff works. E.g. sharing the character movement script would be a good start, maybe along with the physics settings. A screenshot might be useful too.
Another very important aspect is whether you have error messages in your console.

Regarding the downgrading, there is just one person that can be blamed.

1 Like

I don’t get any error in the console. That’s why it’s very weird. And I am using rigidbodies so there is no complex movement coding.
My script is very large and contains so much behaviours , so here is the screenshot of the movement and rotation parts :

When I imported the project , it asked me to make some changes in the script according to the new API.
I pressed yes! What change I have noticed is , where I had “rigidbody” written , it has changed to “GetComponent().” .

Please share the actual code and don’t make screen shots of your code. What’s around those add forces is just as important. Whether they take place in Update or FixedUpdate makes a difference. It is also visible that you are using Mecanim which can have an influence too. But please don’t make us ask all those questions one after another, just show the script and don’t forget to use code tags:

1 Like

Alright dude , I’ll give you my “precious” script! LOL just kidding. Here is the script :

using UnityEngine;
using System.Collections;
/* A Platfromer Controller that enables a player to walk around with Mec'Anim animations setup. Camera behaviour follows the player.
* Rotating view would rotate the character as well. This is done to make the movement a lot easier , so now you don't have to use two sticks for
* both movements.
* Wall Climbing behaviour is also written. Simply jump on a "Wall" tagged object keeping the jump key pressed. The player will start climbing.
* Press and hold "R" to punch.
* Written by Haseeb Ali.
*/
public class PlayerBehaviours : MonoBehaviour {
    public int canWalkCount;
    public int carLeaveCount;
    public Transform carLeavePoint;
    public Transform carRelativeRotationPoint;
    private int inCarCount;
    public bool inCar;
    public CarScript carScript;
    public Transform carSeat;
    public enemy enemyScript;
    public enemy enemyScript2;
    public enemy enemyScript3;
    public int rockCount = 0;
    public int runCount = 0;
    public bool canMove;
    public bool canClimb = true;
    private Vector3 climbEngine;
    public bool climbMove = false;
    private Vector3 distance;
    private int PunchCount = 0;
    private int triggerNumber = 0;
    public int climbSpeed = 11;
    public bool wall1Enabled = false;
    public bool wall2Enabled = false;
    public int otherCount = 0;
    public int walkSpeed;
    private Vector3 mover;
    public Transform player;
    public float rotationSpeed;
    private Vector3 moveDirection;
    public int jumpPower;
    public bool canJump;
    private Vector3 spawnPosition;
    public Transform spawnPoint;
    private Animator _animator;
    public float groundVelocity;
    public float DistanceMovePower;
    public int soundCount = 0;
    public float forces;
    public GameObject particles;
    public GameObject fern;
    public GameObject getParticles;
    public GameObject runParticles;
    public Transform foot;

    // Use this for initialization
    void Start () {

        //GetComponent<Animation>();
        _animator = GetComponent<Animator>();
        _animator.GetFloat("Speed");
        _animator.SetBool("Grounded", false);
        Camera.main.GetComponent<AudioSource>().Play();
        Camera.main.GetComponent<AudioSource>().mute = true;
        GameObject.FindWithTag("Bush").GetComponent<AudioSource>().Play();
        GameObject.FindWithTag("Bush").GetComponent<AudioSource>().mute = true;
        inCarCount = 0;
        canWalkCount = 0;
        _animator.SetBool("CanChange",true);
        fern.GetComponent<AudioSource>().mute = false;
        carScript.transform.GetComponent<AudioSource>().mute = true;
        runParticles.GetComponent<ParticleSystem>().enableEmission = false;

   
    }
   
    // Update is called once per frame
    void FixedUpdate () {
   
        //runParticles.transform.position = foot.position;

        if(inCarCount > 0)
        {
            _animator.SetBool("InCar",true);
        }
        if(inCarCount == 0)
        {
            _animator.SetBool("InCar",false);
        }

        //Vector3 targetDir = player.transform.position - rotationTarget.position;
        //Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, rotationSpeed * Time.deltaTime,0.0f);
        if(inCar == true)
        {
            carScript.transform.GetComponent<AudioSource>().mute = false;
            fern.GetComponent<AudioSource>().mute = true;
            canWalkCount = 0;
            _animator.SetBool("CanChange",false);
            if(Input.GetKeyDown(KeyCode.O) || Input.GetKeyDown(KeyCode.Escape) && carScript.isMoving == false)
            {
                inCarCount -= 1;
                carLeaveCount += 1;
                inCar = false;
            }
            inCarCount += 1;

            transform.rotation = carRelativeRotationPoint.rotation;
            transform.position = carSeat.position;

        }
        if(inCarCount < 1)
        {
            _animator.SetBool("InCar",false);
        }
        if(carLeaveCount > 0)
        {
            transform.position = Vector3.MoveTowards(transform.position,carLeavePoint.position, walkSpeed * Time.deltaTime);
            GetComponent<Rigidbody>().useGravity = false;
        }
        if(transform.position == carLeavePoint.position)
        {
            carScript.carCamera.GetComponent<Camera>().enabled = false;
            canWalkCount += 1;
            carScript.canDrive = false;
            transform.GetComponent<Collider>().enabled = true;
            GetComponent<Rigidbody>().useGravity = true;
            canMove = true;
            canClimb = true;
            canJump = true;

        }

        if(canWalkCount > 0)
        {
            transform.position = transform.position;
            carLeaveCount = 0;
        }
        if(inCar == false)
        {
            carScript.transform.GetComponent<AudioSource>().mute = true;
            fern.GetComponent<AudioSource>().mute = false;
            _animator.SetBool("CanChange",true);
            _animator.SetBool("InCar",false);
            //transform.collider.enabled = true;
        }
        _animator.SetFloat("Speed",groundVelocity);
        climbEngine = new Vector3(0f,Input.GetAxis("Vertical"),0f);

        mover = new Vector3(Input.GetAxis("Vertical"),0,0);

        spawnPosition = new Vector3 (spawnPoint.position.x, spawnPoint.position.y,spawnPoint.position.z);

        if(transform.position.y < 0)
        {
            transform.position = spawnPosition;
        }
        if(canJump == true){
        if(Input.GetKeyDown(KeyCode.Space))
        {
           
            _animator.SetBool("Grounded", true);
            Jump();
            canJump = false;
                GetComponent<AudioSource>().Play();
        }
        }
        if(climbMove == true)
        {
            if(Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow))
            {
                GameObject.FindWithTag("Bush").GetComponent<AudioSource>().mute = false;
            }
            Camera.main.GetComponent<AudioSource>().mute = true;
            groundVelocity = 0.5f;
            _animator.SetBool("CanClimb",true);
            GetComponent<Rigidbody>().AddForce(climbEngine * climbSpeed);
            if(Input.GetKey(KeyCode.Space))
            {

                GetComponent<Rigidbody>().useGravity = false;
            }
            else
            {

                GetComponent<Rigidbody>().useGravity = true;
            }
            if(wall1Enabled == true){
            if(player.transform.position.x < 18.23f || player.transform.position.x > 34.48f)
            {
                GetComponent<Rigidbody>().useGravity = false;
                canMove = true;
                climbMove = false;
            }
            }
        }
        else
        {
            GameObject.FindWithTag("Bush").GetComponent<AudioSource>().mute = true;
        }

        if(climbMove == false)
        {
            GetComponent<Rigidbody>().useGravity = true;
        }

        if(wall1Enabled == true){
        if(player.transform.position.y > 13.23f)
        {
            GetComponent<Rigidbody>().useGravity = true;
            climbMove = false;
            canMove = true;
            wall1Enabled = false;
                canJump = true;
        }
        }


        if(Input.GetKey(KeyCode.R))
        {
            PunchCount = 0;

            if(PunchCount == 0)
            {
                _animator.SetInteger("PunchCount",2);



            }


        }
        else
        {
            _animator.SetInteger("PunchCount",0);
        }

        if(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.Escape) && Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
        {
            runCount = 0;


            if(runCount == 0)
            {
                   
                _animator.SetInteger("RunCount",2);
                walkSpeed = 30;
                //runParticles.particleSystem.enableEmission = true;

               
            }

           
           
        }
        else
        {
            //runParticles.particleSystem.enableEmission = false;
            _animator.SetInteger("RunCount",0);
            walkSpeed = 18;
        }
        //if(Input.GetKey(KeyCode.LeftArrow))
        //{


            //transform.rotation = Quaternion.RotateTowards(transform.rotation,Quaternion.AngleAxis(360f, Vector3.left), rotationSpeed * Time.deltaTime);
        //}

         
        //if(Input.GetAxis("Mouse X") > 0.1f || Input.GetAxis("Mouse X") < -0.1f)
        if(canMove == true){
            if(Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow))
            {
                Camera.main.GetComponent<AudioSource>().mute = false;
            }
            else
            {

                Camera.main.GetComponent<AudioSource>().mute = true;
            }
            _animator.SetBool("CanClimb",false);
        GetComponent<Rigidbody>().AddRelativeForce(mover * walkSpeed);
            if(Input.GetAxis("Horizontal") > 0.1f || Input.GetAxis("Horizontal") < -0.01f)
            {
                player.Rotate(0f, Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime, 0f);
               
            }

        }

        if(canMove == true){
            if(Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S))
        {

            //GameObject.FindWithTag("Playera").
            //animation.CrossFade("Armature|Walk");
            groundVelocity = 0.6f;
           
           

           
           
        }

        else if(groundVelocity == 0f){
            //animation.CrossFade("Armature|Idle");
            _animator.SetFloat("Speed",0f);
        }
        else
        {
            groundVelocity = 0f;
        }
           

        }

        if(wall2Enabled == true)
        {
            if(transform.position.y > 20f)
            {
                canMove = true;
                climbMove = false;
                GetComponent<Rigidbody>().useGravity = true;
                wall2Enabled = false;
                canJump = true;
            }
        }

        if(Input.GetKeyDown(KeyCode.C))
           {
            _animator.SetTrigger("The Trigger");
            triggerNumber += 1;
        }
        if(triggerNumber > 0)
        {
            if(Input.GetKey(KeyCode.UpArrow))
            {
                _animator.SetBool("CanCrawl",true);
                //player.rotation = Quaternion.LookRotation(newDir);
            }
            else
            {
                _animator.SetBool("CanCrawl",false);

            }
        }

        if(canJump == false)
        {
            Camera.main.GetComponent<AudioSource>().mute = true;

        }

   



    }
   
   

void OnCollisionEnter(Collision other)
{


    if(other.collider.tag == "Plane")
    {
            _animator.SetBool("CanChange",true);
            transform.GetComponent<Collider>().enabled = true;
            _animator.SetBool("Fall2Walk",true);
            wall1Enabled = false;
            wall2Enabled = false;
        groundVelocity = 0.6f;
        canMove = true;
        climbMove = false;
        canJump = true;
            _animator.SetBool("Grounded",false);
            _animator.SetBool("CanClimb",false);

    }

        if(other.collider.tag == "Wall" && Input.GetKey(KeyCode.Space))
        {
            //rigidbody.AddForce(Vector3.back * DistanceMovePower);
            climbMove = true;
            canMove = false;
            _animator.SetBool("Grounded",false);
            _animator.SetBool("CanClimb",true);
            wall1Enabled = true;


        }

        if(other.collider.tag == "Wall2" && Input.GetKey(KeyCode.Space))
        {
            //rigidbody.AddForce(Vector3.back * DistanceMovePower);
            climbMove = true;
            canMove = false;
            _animator.SetBool("Grounded",false);
            _animator.SetBool("CanClimb",true);
            wall2Enabled = true;

           
        }

   

        if(other.collider.tag == "Enemy" && canJump == false)
        {
            Destroy(GameObject.FindWithTag("Enemy"));
            Instantiate(particles,enemyScript.self.position,Quaternion.Euler(270,0,0));
        }

        if(other.collider.tag == "Enemy" || other.collider.tag == "Enemy2" || other.collider.tag == "Enemy3" && canJump == true)
        {
            GetComponent<Rigidbody>().AddRelativeForce(Vector3.back * forces);
        }

        if(other.collider.tag == "Enemy" || other.collider.tag == "Enemy2" || other.collider.tag == "Enemy3")
        {
            GetComponent<Rigidbody>().AddRelativeForce(Vector3.up * forces);
        }

        if(other.collider.tag == "Enemy2" && canJump == false)
        {
            Destroy(GameObject.FindWithTag("Enemy2"));
            Instantiate(particles,enemyScript2.self.position,Quaternion.Euler(270,0,0));
        }

        if(other.collider.tag == "Enemy3" && canJump == false)
        {
            Destroy(GameObject.FindWithTag("Enemy3"));
            Instantiate(particles,enemyScript3.self.position,Quaternion.Euler(270,0,0));
        }



   

   
   
   
   
   
}

void Jump()
{
    GetComponent<Rigidbody>().AddForce(Vector3.up * jumpPower);
}

    void OnTriggerEnter(Collider other)
    {
        if(other.GetComponent<Collider>().tag == "Door1")
        {
            GameObject.FindWithTag("Door").GetComponent<Animation>().Play("Door2");
        }

        if(other.GetComponent<Collider>().tag == "Car")
        {
            inCar = true;
            carScript.canDrive = true;
            canMove = false;
            canJump = false;
            canClimb = false;
            transform.GetComponent<Collider>().enabled = false;

            //print("detected");

        }



        if(other.GetComponent<Collider>().tag == "Rock" || other.GetComponent<Collider>().tag == "Rock1" || other.GetComponent<Collider>().tag == "Rock2" || other.GetComponent<Collider>().tag == "Rock3"
           || other.GetComponent<Collider>().tag == "Rock4" || other.GetComponent<Collider>().tag == "Rock5" || other.GetComponent<Collider>().tag == "Rock6" || other.GetComponent<Collider>().tag == "Rock7"
           || other.GetComponent<Collider>().tag == "Rock8" || other.GetComponent<Collider>().tag == "Rock21" || other.GetComponent<Collider>().tag == "Rock22" || other.GetComponent<Collider>().tag == "Rock35"
           || other.GetComponent<Collider>().tag == "Rock9" || other.GetComponent<Collider>().tag == "Rock20" || other.GetComponent<Collider>().tag == "Rock23" || other.GetComponent<Collider>().tag == "Rock34"
           || other.GetComponent<Collider>().tag == "Rock10" || other.GetComponent<Collider>().tag == "Rock19" || other.GetComponent<Collider>().tag == "Rock24" || other.GetComponent<Collider>().tag == "Rock33"
           || other.GetComponent<Collider>().tag == "Rock11" || other.GetComponent<Collider>().tag == "Rock18" || other.GetComponent<Collider>().tag == "Rock25" || other.GetComponent<Collider>().tag == "Rock32"
           || other.GetComponent<Collider>().tag == "Rock12" || other.GetComponent<Collider>().tag == "Rock17" || other.GetComponent<Collider>().tag == "Rock26" || other.GetComponent<Collider>().tag == "Rock31"
           || other.GetComponent<Collider>().tag == "Rock13" || other.GetComponent<Collider>().tag == "Rock16" || other.GetComponent<Collider>().tag == "Rock27" || other.GetComponent<Collider>().tag == "Rock30"
           || other.GetComponent<Collider>().tag == "Rock14" || other.GetComponent<Collider>().tag == "Rock15" || other.GetComponent<Collider>().tag == "Rock28" || other.GetComponent<Collider>().tag == "Rock29")
        {
            GameObject clone = Instantiate(getParticles,other.GetComponent<Collider>().transform.root.position,getParticles.transform.rotation) as GameObject ;
            Destroy(other.GetComponent<Collider>().transform.root.gameObject);
            Destroy(clone,2f);
            rockCount += 1;
        }
   

    }

    void OnCollisionExit(Collision other)
    {
        if(other.collider.tag == "Plane")
        {
            _animator.SetBool("Fall2Walk",false);



        }



    }

}

I’m sorry if this looks so messy and unarranged to you :slight_smile:

The reason why it might look messy could be that it actually is pretty messy…

You have a lot of things like:

transform.position = ...;

If you are using forces and gravity, you should try to avoid setting the position like that, because it can lead to weird issues. You need to systematically find out e.g. while the character is falling what modifications you are making and then check what is the cause for it.
I fear it won’t be too easy to analyze it with this kind of script.

1 Like

Hehe I guess I’ll find a way to fix this. Anyways , thanks a lot for your concern and help :slight_smile: