Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by Sirex1 · Feb 17 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. This is done in a Update function. The boxes are also created when it hits 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 switching 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[] hits;
         hits = Physics.BoxCastAll(radarSweepCollider.bounds.center, radarSweepTransform.localScale, radarSweepTransform.forward, radarSweepTransform.rotation, 500, RadarLayer);
         foreach(RaycastHit hit in hits) {
            if(hit.distance > 5) {
                 var nextHit = HitList.AdvanceNext();
                 var nextHitScript = nextHit.GetComponent<RadarBlipScript>();
                 nextHitScript.gameObject.SetActive(true);
                 nextHitScript.ResetAppearTime();
                 nextHit.position = hit.point;
                 nextHit.rotation = Quaternion.identity;
                 targetProcessor.AddRadarHit(nextHit);
            }
        } 
 
     }
Comment
Add comment
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
1
Best Answer

Answer by Shrimpey · Feb 17 at 03:46 PM

Game is not switching to fixedUpdate, but it's probably turning VSync ON by default for the build. This 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 things 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
Add comment · 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.

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

How to get Raycast surface normal to align particle system? 1 Answer

Detect if on ground? 1 Answer

RayCast offset rotation 20 degrees 1 Answer

Rigidbody.AddForce with Raycast? 1 Answer

Look At Player with Clamping. 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