- Home /
When a lot is happening in my game some frame dont run this simple script
Greetings,
I have a game in which the player runs through dungeons. All monsters and the player as well as many elements in game that are 2d and are rendered at an angle that faces the camera. The camera looks down at the world at a 45% degree angle (isometric like) so I can make a mix of 2d and 3d elements.
At times when a lot is happening the script that controls this is ignored and everything, never individual things are all rendered at a 0% degree angle making them look like they are lying down.
It only happens when there is a lot on the screen or when I have been working for a long time. perhaps something to do with memory or something?
the script is as follows:
public class FaceCamera : MonoBehaviour {
public Transform target;
void Start()
{
target = GameObject.Find("MainCamera").GetComponent<Transform>();
}
void Update()
{
if (target != null)
{
this.transform.rotation = Camera.main.transform.rotation;
}
}
}
Does anyone have a suggestion of what this could be and where I can look further to solve this issue?
Answer by Bunny83 · Jul 30, 2018 at 06:04 PM
What is the point of the "target" variable? You don't use it beside the null check. did you mean to do:
target.rotation = Camera.main.transform.rotation;
Currently your script does rotate the object this script is attached to. Though if that's the purpose, what is that target good for?
btw: Does the camera ever change it's rotation? If not there should be no reason to set the rotation every frame. Once at start would be enough.
Hi thanks for your answer.
yes it is necessary to check more than just at start as my camera also rotates around its axis the characters will rotate to look at it. think "realm of the mad god". But im redoing the script and will see if it works better if I just tell it to update only when necessary not every frame. ill update if it works.
did this:
public class FaceCamera : $$anonymous$$onoBehaviour {
public Transform targetRotation;
void Start()
{
targetRotation = GameObject.Find("$$anonymous$$ainCamera").GetComponent<Transform>();
}
void Update()
{
if (targetRotation != null)
{
if (targetRotation.rotation != transform.rotation)
{
transform.rotation = targetRotation.rotation;
}
}
}
}
but its still doing it, worse now acctually.
Your answer
Follow this Question
Related Questions
Isometric tiles depth 0 Answers
Ortho-Isometric camera not playing nice with culling 1 Answer
Sprite rendering order on perspective camera 1 Answer
Error while creating an object 0 Answers