Physics and Rendering Optimization Issues
So the past two weeks I've been working on a rather simple game. The whole game is pretty much directing a a cube with the camera attached through a bunch of obstacles (Imagine a star fox endless runner). The game is now for the most part finished except for the few optimization problems I've been having.
That is a screenshot I took while profiling my game and as far as I can tell both rendering and physics are using up a ridiculous amount of the cpu. I have absolutely no idea why this is, the only thing I'm really doing with physics is setting the cube's x and y velocity based on the Horizontal and Vertical axes as well as increasing the velocity on the z axis by 10 * Time.deltatime each frame so that you speed up and it gets harder to avoid the obstacles. As for rendering the only taxing thing I can think of would be that I'm using a post processing profile with occlusion turned on but nothing else. Below is the code that controls the cubes velocity, it is the only script in my project that does anything with physics so i assume this is where the problem is coming from.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShipController : MonoBehaviour
{
[SerializeField] private Rigidbody rb;
private float speed = 1000;
private Vector3 SetVelocity;
private float forwardVelocity = 1;
private void Update ()
{
//Controls acceleration and speed limit.
speed += 10 * Time.deltaTime;
speed = Mathf.Clamp(speed, 0, 2700);
//Sets velocity based on input from the x and y axis as well as the forwardVelocity value.
SetVelocity = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), forwardVelocity);
SetVelocity *= speed;
}
private void FixedUpdate()
{
rb.velocity = SetVelocity * Time.deltaTime;
}
}
Originally I was setting the velocity inside of Update itself but I decided to change it because I'd heard somewhere that FixedUpdate was more tailored towards physics, however doing this didn't help at all. I have absolutely no Idea why this is happening so any help would be appreciated and also if you have any idea why rendering might be using up so much of the cpu that would also be appreciated! P.s. for the games visuals I'm only using the base unity cubes except at different scales and rotations and there is only ever a max of 10 of them in the scene at once.
Your answer
Follow this Question
Related Questions
Draw Calls are still HIGH? 0 Answers
,DoRenderLoop_Internal() - How would you optimize this for Android and Iphone? 0 Answers
Looking For Tips On Optimizing Camera Rendering To Increase Framerate 1 Answer
Camera still rendering everything even when using occlusion culling 1 Answer
profiler showing vsync is main cause for performance issues. while vsync is of in quality settings. 0 Answers