Good day dear Unity community.
My team is working on a game and we finally reached the point of finishing the map assets, which happens to be a city. I imported everything last night and started to work with it today.
After putting all assets there, lots of assets as you may see in the following picture, something expected happened: I got an FPS drop. What is odd to me is that the FPS drop (of about 160 FPS!) wasn’t caused by the new assets’ rendering, at least that’s what the profiler said. Checking the profiler I was able to isolate the source of the FPS drop, and it happens to be my movement script.
Before I imported the assets I used the same movement script, I actually used the same scripts I have now for core gameplay testing purposes, and I noticed nothing, I had like 250 FPS, but there were no assets to truly work the rendering, so I expected a loss after the assets were imported, but now such big loss, and surely not because of the collider script.
I wasn’t aware that Physics.Simulate can eat so much FPS, and checking the forunms and unityanswers, I was not the only one surprised by such, and I use a very simplistic movement script, which is possibly shadowing my judgement of what is going on… I have no idea.
Can any good soul give me a light here?
This is a picture showing the FPS difference with the script on and off, as well as the settings around,also, both pictures have directional light on.
This is the script:
#pragma strict
//Movement Calculation Variables
private var runSpeed = 2.0; //Running Speed
private var walkSpeed = 1.0; //Walking Speed
private var controller : CharacterController; //Character Controller Caller
private var hRotation : float;
var horizontal = Horizontal();
var rotationObject : GameObject;
@HideInInspector
//Function Start
function Start () {
controller = GetComponent(CharacterController); //Getting the character controller
}
//Function Update
function Update () {
//Here we calculate the movement variables
var up = cInput.GetButton ("Forward"); //Movement Button
var dwn = cInput.GetButton("Backward"); //Movement Button
var lft = cInput.GetButton("LeftStrafe"); //Movement Button
var rgt = cInput.GetButton("RightStrafe"); //Movement Button
var aim = cInput.GetButton ("Aim"); //Aim Setting
var run = cInput.GetButton ("Run");
var rotation = cInput.GetAxis("Mouse X");
if (up && dwn) return; //Conflict Move Cancel
if (lft && rgt) return; //Conflic Move Cancel
var i = 0; //Aim Movement Variable
if (run)
i = 1;
if (aim)
i = 0.1;
var move = Vector3.zero; //Our Movement Variable
if (up)
move += transform.forward; //Forward Move
if (dwn)
move -= transform.forward; //Backward Move
if (rgt)
move += transform.right; //Right Move
if (lft)
move -= transform.right; //Left Move
if (rotation)
transform.Rotate(0, rotation * 2, 0);
if (i == 0)
move *= walkSpeed;
else if (i == 1)
move *= runSpeed;
else if (i > 1)
move *= walkSpeed;
controller.SimpleMove(move); //Movement Variable
hRotation += cInput.GetAxis("Mouse X") * horizontal.mouseSensitivity ;
hRotation = AngleClamp( hRotation, horizontal.minimumAngle, horizontal.maximumAngle);
rotationObject.transform.localEulerAngles.y = hRotation;
}//End of script
function AngleClamp ( rotation : float , min : float, max : float) {
if(rotation < -360)
rotation = rotation + 360;
if(rotation > 360)
rotation = rotation - 360;
rotation = Mathf.Clamp(rotation, min, max);
return rotation;
}
This is the picture of both scenarios:
Since now I appreciate the attention and help.