• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Sirex1 · Feb 17, 2022 at 03:05 PM · rotationraycast

Rotation+BoxCast works with Update in game editor, but not when built or in FixedUpdate.

Hi! I'm making a mech game where you can enter a secondary seat to see a radar. We want to model the radar a little bit more, so it rotates a box on the mech then casts Physics.BoxCastAll and than creates small red boxes where it collides. The boxes are in a radar layer so only viewable from the navigator camera. T$$anonymous$$s is done in a Update function. The boxes are also created when it $$anonymous$$ts terrain that sticks up.

It works great when I press play in the editor. But when I build and play there are very large spaces between the boxes ( radarBlips ) that get's created. I tried changing to FixedUpdate and noticed the same behavior. Is the game switc$$anonymous$$ng to FixedUpdate when you build? In the editor play I hover around 180-240fps, if that plays a part. HitList is a pool of radarblip boxes that I reuse to improve performance.

 public class RadarSweepScript : MonoBehaviour
 {
     [SerializeField] public Transform RadarBlip;
     public RadarHitList<Transform> HitList;
     private Transform radarSweepTransform;
     private Transform mechTransform;
     public float rotationSpeed;
     public float radarDistance;
     [SerializeField] public LayerMask RadarLayer;
     private RadarTargetComputer targetProcessor;
     private Collider radarSweepCollider;
     private bool radarOn = true;
     public bool RadarOn { get => radarOn; set => radarOn = value; }
     private float xSweepRotationAngle;
     
     // Start is called before the first frame update
     void Awake()
     {
         radarSweepTransform = transform;
         radarSweepCollider = radarSweepTransform.GetComponent<Collider>();
         mechTransform = transform.parent.parent;
         targetProcessor = gameObject.GetComponent<RadarTargetComputer>();
     }
 
     void Start()
     {
         HitList = new RadarHitList<Transform>(300);
         for (int i = 0; i < 300; i++)
         {
             var radarblip = Instantiate(RadarBlip, transform.position + Vector3.down*5, new Quaternion());
             HitList.Add(radarblip);
         }
     }
 
     void Update()
     {
         if(!radarOn)
             return;
         //radarSweepTransform.eulerAngles -= new Vector3(0, rotationSpeed * Time.deltaTime, 0);
         xSweepRotationAngle -= Time.deltaTime * rotationSpeed;
         radarSweepTransform.rotation = Quaternion.Euler(0, xSweepRotationAngle, 90);
         
         RaycastHit[] $$anonymous$$ts;
         $$anonymous$$ts = Physics.BoxCastAll(radarSweepCollider.bounds.center, radarSweepTransform.localScale, radarSweepTransform.forward, radarSweepTransform.rotation, 500, RadarLayer);
         foreach(RaycastHit $$anonymous$$t in $$anonymous$$ts) {
            if($$anonymous$$t.distance > 5) {
                 var nextHit = HitList.AdvanceNext();
                 var nextHitScript = nextHit.GetComponent<RadarBlipScript>();
                 nextHitScript.gameObject.SetActive(true);
                 nextHitScript.ResetAppearTime();
                 nextHit.position = $$anonymous$$t.point;
                 nextHit.rotation = Quaternion.identity;
                 targetProcessor.AddRadarHit(nextHit);
            }
        } 
 
     }
Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Shrimpey · Feb 17, 2022 at 03:46 PM

Game is not switc$$anonymous$$ng to fixedUpdate, but it's probably turning VSync ON by default for the build. T$$anonymous$$s forces the game to run 60 fps (or other FPS equal to your display's refresh rate). There is a setting for turning vsync off. But you shouldn't just leave vsync off and call it a day. You need consistent behaviour that's not dependant on user's framerate and you should program physics related t$$anonymous$$ngs in FixedUpdate. Do your programming in FixedUpdate, maybe adjust your rotationSpeed to work well in FixedUpdate or some other variables and you should be fine.

Comment
Sirex1

People who like this

1 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

222 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Raycasting from object rotation? 1 Answer

click to move workig script!! but pls help with rotation!! :( 1 Answer

How do I get an object to rotate around a different axis based on the raycasts hit angle? 0 Answers

Rotate Object relative to a other(I dont get it after 5 days google searching! pls) 2 Answers

Help finding out which side of a cube a raycast hits 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges