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 /
avatar image
0
Question by Salmando · Apr 11, 2017 at 03:39 AM · unity 5getbuttondown

Input.GetButtonDown("Fire1") not working while 'moving'

Hi everyone,

I'm trying to destroy a cube by using a raycast to hit it every time i press the left mouse button. While standing perfectly still, this seems to work flawlessly. However, once my character is moving - even if just falling - the GetButtonDown command doesn't seem to register.

Code Below

 void Update()
 {
     
     if (Input.GetButtonDown("Fire1"))
     {
         Debug.DrawRay(transform.position, transform.forward * 1000f, Color.green, 1000f);
         shooting = true;
     }
 }
 void FixedUpdate()
   {
     if (shooting)
     {
         RaycastHit hit;
         if (Physics.Raycast(transform.position, transform.forward, out hit, 1000f))
         {
             if (hit.transform.tag == "Killable")
             {
                 hit.collider.SendMessage("Hurt", damage, SendMessageOptions.DontRequireReceiver);
                 GameObject bloodcopy;
                 Blood.transform.position = hit.point;
                 bloodcopy = Instantiate(Blood, hit.point, Quaternion.identity);
                 GameObject.Destroy(bloodcopy, .3f);
             }
         }
         shooting = false;

     }
 }

At first i thought it had something to do with the raycast itself while i was moving, I turned on drawing of the cast to help see what was happening, but couldn't see it. I then moved the draw to where it is above, and discovered that it would never draw while moving, but always draw when not moving.

What is going on?

Comment
Add comment · Show 4
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 Salmando · Apr 10, 2017 at 10:26 AM 0
Share

Update: Using left CTRL key works perfectly, so the issue is only with mouse click.

avatar image estevan95 · Apr 11, 2017 at 02:22 PM 0
Share

You are shooting from your characters's forward. It he moves, the forward may not face that cube and hit the shot. Unity Input should always register.

avatar image Salmando estevan95 · Apr 11, 2017 at 02:29 PM 0
Share

The problem is that it isn't registering. Ignoring the cube, when i use the left mouse button while the character controller is in motion, the raycast is never drawn. By comparison, while moving and pressing left control key, the raycast is drawn. When the character controller isn't in motion (looking around is fine), the left mouse button does trigger and the ray is drawn.

avatar image FortisVenaliter · Apr 11, 2017 at 03:59 PM 0
Share

Have you tried adding a Debug.Log statement to the if check in Update?

I would sprinkle a few Debug.Logs in there to deter$$anonymous$$e where the issue is. It's unlikely that it's with the Input call.

$$anonymous$$ore likely, the issue is with the raycast hitting the source collider.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Cuttlas-U · Apr 11, 2017 at 08:54 AM

hi; Try using " if (Input.GetButtonDown(0))"

see if that helps;

I can't think any thing out of this , seem u did it all correct;

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Lerp in Coroutine (Crazy Behavior) 2 Answers

How long would it take to make a 2d game? 0 Answers

Problem importing "survival shooter" 0 Answers

shotgun like action 1 Answer

Rotation of wheels of a car 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