• 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
1
Question by MiroslavMilanov · Oct 03, 2018 at 06:00 PM · collisionmovementtimeframeratetimescale

Is it a bad practice to change the timescale for the whole game?

I have a player that shoots out projectiles (arrows). Since they do not move instantaneously, I transform.translate to move them. However, they travel very quickly and "skip" along the screen with each frame. The problem is collisions. If the arrow is too fast, it may skip through an enemy. (The game is 2D by the way.) The arrow can also pierce for an X amount of times. If I want it to pierce for example 1 time before destroying itself, but there are four enemies in the same spot, all collision events happen simultaneously and it pierces 3 times instead of 1. I've tried to illustrate as best as I can here: alt text I've tried different kind of movements for the arrow, but so far I didn't find out anything worthwhile. The only thing I can think of is to raise the Timescale and lower variables such as movement speed, animations speed, etc. My only concerns are if this will change time.deltaTime and if it is a good practice whatsoever.

My question is about changing the Timescale, but if you have any suggestions about how to better handle the arrow movement, I'm open.

untitled.png (15.7 kB)
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
2

Answer by Casiell · Oct 04, 2018 at 06:44 AM

I don't think this is a good idea. You will have a lot of work changing it and remembering about it every time you add something new. Eventually it will have consequences that you won't really anticipate and you will have a lot of problems finding out why something happens. It's not necessarily a bad thing, but for a standard operation like shooting arrow it's certainly an overkill.

You could share the whole portion of your code that moves the arrow, it will be easier to "fix" it this way.

Quick tip: there is Time.unscaledDeltaTime if you really need to change timeScale

Comment
Add comment · Show 6 · 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
avatar image MiroslavMilanov · Oct 04, 2018 at 07:59 AM 0
Share
     void Update () {
         this.transform.Translate(new Vector2(1,0) * arrowSpeed * Time.deltaTime);
     }

Is the code. I've set the rotation of the arrow in another segment of code, so all I need is the arrow to move forward smoothly. I also considered raycasting, but to my knowledge that happens instantaneously and doesn't go well with a slow-moving arrow.

avatar image Casiell MiroslavMilanov · Oct 04, 2018 at 08:31 AM 0
Share

You should use FixedUpdate for moving objects. Also if you have RigidBody you should probably use Rigidbody.$$anonymous$$ovePosition. It calculates collisions at the same time as movement (not exactly, but close enough) so detection should be better. Also your RigidBody should have collision detection on Continous for moving objects

Also small tip: use Vector2.Right ins$$anonymous$$d of new Vector2(1,0), it doesn't create new objects every frame so it's friendlier for GC, also more readable.

avatar image MiroslavMilanov Casiell · Oct 04, 2018 at 06:03 PM 0
Share

I will use all your tips from now on. Thank you very much for the suggestions. First I tried just setting the collision detection to continuous. The problem persisted. Then I changed the code to Rigidbody.$$anonymous$$ovePosition, however the arrow stopped moving forward completely. The arrow gameObject has a Rigidbody 2d component, that is $$anonymous$$inematic and Simulated. I haven't locked any of the axis.

Show more comments
Show more comments

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

185 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

Related Questions

trying to regulate character speed. 1 Answer

How to detect collision when Time.timeScale == 0? 2 Answers

How do I make colliders collide when Tİme Scale is zero? 1 Answer

Box collider (with Rigidbody attached) gets stuck into another Box Collider 0 Answers

Player movement ignores some collision 0 Answers


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