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 odinpower22 · Feb 18, 2014 at 01:51 PM · shootingbulletprojectileshootfiring

How to avoid speed change in bullets while moving?

I've seen many examples about shooting in unity using the physics approach and the transform too but something I was wondering is how to prevent bullets from changing speed while moving.

The Space Shooter Project by Unity guys is an example and you can download for free from the asset store. Here is the link in someone is interested:

link text

As you can see in the example or in general, if you shoot without pressing any up/down key the bullets look with one speed but as soon as you press upwards while shooting the projectiles increse speed and vice versa while pressing backwars, I mean the bullets slow down until you get stuck at the bottom of the screen when the speed of the projectiles looks the same as you where not pressing any key while shooting.

A diagram would be:

Only Shooting : BULLET space space BULLET space space BULLET (Normal Speed)

Shooting + UP : BULLET space BULLET space BULLET (Fastest Speed)

Shooting + DOWN: BULLET space space space space BULLET space space space space BULLET (Slowest Speed)

Thanks in advance and sorry for my english I'm still learning ;-)

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
0

Answer by AnXgotta · Feb 18, 2014 at 02:21 PM

What I think you are talking about is fire rate. If we look at the code that you linked, in the file called "Shooting Shots" there is this block that controls the shooting:

  void Update ()
     {
         if (Input.GetButton("Fire1") && Time.time > nextFire)
         {
             nextFire = Time.time + fireRate;
             Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
             audio.Play ();
         }
     }

This is the important line:

 if (Input.GetButton("Fire1") && Time.time > nextFire)

So what is happening is the user clicks the left mouse button and if enough time has passed such that the current time is greater that the 'nextFire' time, then we can shoot again. Think about this... you see here:

 nextFire = Time.time + fireRate;

So, depending on what you set 'fireRate' to determines the literal fire rate.

Example:

fireRate = 0.5f will give you 2 shots every second.

fireRate = 0.1f will give you 10 shots every second.

So what I would guess is happening is that when the user holds 'UP', it assigns a small value to 'fireRate' and the opposite for when the user holds 'DOWN'.

Comment
Add comment · Show 5 · 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 odinpower22 · Feb 18, 2014 at 03:21 PM 0
Share

AnXgotta, first thanks for your answer. And let me tell you that I've been playing with the 'fire rate' changing it on the fly according to the up/down key pressed in an attemp to compesate the effect but it didn't work.

Besides, the 'fire rate' in the script, this in particular and many others I've seen, doesn't change at all. It's always the same. I guess it has something to do with the player and bullet speeds. I've made some tests sum$$anonymous$$g those speeds but didn't work either.

Is it possible to solve the issue? Thanks again!

avatar image AnXgotta · Feb 18, 2014 at 04:03 PM 0
Share

Just to clarify... you do mean that the player shoots bullets faster or slower when moving up and down? Not that the bullet projectiles move faster or slower after being fired, correct?

avatar image odinpower22 · Feb 18, 2014 at 04:20 PM 0
Share

Exactly, when moving up/down the bullets seems to travel faster/slower respectively even though the fire rate won't change.

For example, while pressing up and shooting the bullets look closer compared to when shooting only.

Again, 'AnXgotta' thanks for your patience.-

avatar image AnXgotta · Feb 18, 2014 at 04:31 PM 0
Share

Ok. Your two sentences mean opposite things. We need to clarify again.

"when moving up/down the bullets seems to travel faster/slower respectively even though the fire rate won't change" = same fire rate, bullet projectile speed is variant.

"while pressing up and shooting the bullets look closer compared to when shooting only" = bullet projectile speed is same, fire rate is variant.

So is it: 1) Bullet projectiles speed is always the same, the fire rate is changing or 2) Bullet projectiles speed is changing, fire rate is always the same

I would load the project and look but I can't because I'm at work.

avatar image odinpower22 · Feb 18, 2014 at 05:15 PM 0
Share

Ok, I'll try to clarify: I won't talk about speed or fire rate only about what I'd like to see on screen and that is "I'd like to keep the distance beetween bullets constant independently of pressing up/down while shooting".

And about loading the project right now there's no problem. I'll keep checking back until finding a solution.

Thank you 'AnXgotta'.-

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

19 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

Related Questions

Issues with bullet not subtracting properly 1 Answer

How to Sync bullet spawn with shoot animation 0 Answers

Air Strike shoot aiming at cross hairs in middle of the screen 2 Answers

Shooting & Animation Problem 1 Answer

How do i adjust the projectile path and direction? 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