Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Kodl · Oct 11, 2017 at 12:46 PM · androidpositiondistancemovebullet

Peculiar problem with frame-based bullets generator

I have very interesting problem with frame-based bullet generating and changing speed.

Imagine schmup type game. Bullets are shot from right to left horizontaly in line. After completing one round/wave speed is raised by 10%. Until speed is doubled. Then keep that double speed.

Problem is that gap between bullets in one round is slightly different from gap size in other round with different speed. I think that this is happening because of Mathf.RoundToInt(framesBetweenBullets).

1 sec = 30 frames TimeBetweenBullets = 1f(sec) SpeedChanger = 1f - 2f

30 * (TimeBetweenBullets / SpeedChanger); this number is not round, but i need Int for frame based, so after Round.Int i lose precision. but even if i double speed to 2 and frames between shots are at half (15) (all Ints) the gap is larger and i don't know why.

Few thoughts: it seems like nonsense to cut frames between shots by 10% from 30 to 15 frames to achieve double speed and multiply bullet speed from 1 to 2 with same variable.

i don't need that bullet speed is raised by precise 10%. so i have tried to store ratio from rounded variable framesBetweenBullets. and use that to modify bullet speed with no success.

i need some magic:) number that will multiply bullet speed (and many other things in my game) to correct speed with dependecy on rounded framesBetweenBullets number, i think.

Can someone from ADVANCED programmers help me?

And please don't write anything with Time.DeltaTime, which i think is completely useless in most part of any game.

Sorry for my bad english. Small clean example project in attachment (U2017.1) Switch to android project and disable V Sync Count in QualitySettings to allow 30 FPS.

code example Bullet.cs: void Awake(){ targetFPSrate = (1f / targetFPS); }

 public void UpdateMove(){
     m_transform.position += m_transform.up * ((m_speed * speedChanger) * targetFPSrate);
 }

it seems that when i multiply m_transform.up with some number 30 times per second, object is moving differently than with multiply m_transform.up with double the some number 15 times per second. it should be moving the same distance, i think.

code example ShotBase.cs:

 public void Update() {
     framesCounter++;
     if (framesCounter > framesBetweenShotsRounded)
     {
         ShotBullet(m_Bullet, m_BulletSpeed, m_SpeedChanger);
     }
 }
 public void Shot() {
         framesBetweenShotsNotRounded = targetFPS * (m_BulletBetweenTime / m_SpeedChanger);
         framesBetweenShotsRounded = Mathf.RoundToInt(framesBetweenShotsNotRounded);
         framesCounter = framesBetweenShotsRounded;
 }


alt text

shotratespeedtest.png (224.9 kB)
shotratespeedtest.zip (227.0 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

0 Replies

· Add your reply
  • Sort: 

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

206 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

Related Questions

Move 3d object using touch android 0 Answers

Unity Smooth Move and Zoom UI on Canvas for Android/IOS 0 Answers

Show / Hide GUI Button - Enable / Disable Script (Android) 0 Answers

Why is my gameObject in a different position on galaxy s4? 1 Answer

How to get position of enemy 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