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 /
This question was closed May 14, 2018 at 01:27 AM by Fibonacci_0_1_1 for the following reason:

I solved the problem

avatar image
0
Question by Fibonacci_0_1_1 · May 12, 2018 at 08:07 PM · raycastshootingraycastingraycasthitraycasts

Raycast is constrained to the horizontal axis

SOLVED

The transform.forward is contained to the horizontal axis. it doesn't rotate vertically making my weapon shoot horizontally even when my weapon is pointing upwards. any ideas as to why this is happening? thanks!

Here's my code:

 if (Physics.Raycast (arv2.transform.position,
                 arv2.transform.forward, out hit_var, wep_range) &&
                 Time.time >= time_to_fire) {
 
                 Debug.DrawRay (arv2.transform.position,
                     arv2.transform.forward,Color.red);
 
                 time_to_fire = Time.time + 1f / fire_rate;
                 shooting = true;
 
                 Debug.Log ("arv2 hit");
                     
             } 

SOLUTION:

The problem had to do with my Timestep. My Timestep was set to 0.002, I switched it back to default 0.02 and the problem went away.

Go to:

edit - project settings - Time

  • Now edit the Timestep

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

  • Sort: 
avatar image
0

Answer by BGOKMEN14 · May 13, 2018 at 04:49 AM

Hello @Fibonacci_0_1_1,

The reason that is the case is because you are using transform. forward, meaning the raycast is restricted horizontally.

When looking up, is the arv2 also rotated?

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 Fibonacci_0_1_1 · May 13, 2018 at 01:23 PM 0
Share

Yes, when i Look up, arv2 is rotated accordingly. While playing the game with arv2 selected in the editor window in global mode, i can clearly see the blue arrow adjusting properly. For some reason my raycast is constrained horizontally but may RARELY point exactly where I want it to point.

avatar image BGOKMEN14 Fibonacci_0_1_1 · May 13, 2018 at 04:02 PM 0
Share

Hello again! I found the problem ins$$anonymous$$d of using transform.forward, you need to use "transform.TransformDirection(Vector3.forward)"

So it would look like this:

  if (Physics.Raycast (arv2.transform.position,
                  arv2.transform.forward, out hit_var, wep_range) &&
                  Time.time >= time_to_fire) {
  
                  Debug.DrawRay (arv2.transform.position,
                      arv2.transform.TransformDirection(Vector3.forward) ,Color.red);
  
                  time_to_fire = Time.time + 1f / fire_rate;
                  shooting = true;
  
                  Debug.Log ("arv2 hit");
                      
              } 

I hope this helps and have a great day

avatar image Fibonacci_0_1_1 BGOKMEN14 · May 13, 2018 at 06:21 PM 0
Share

I tried replacing

arv2.transform.forward

with

arv2.transform.TransformDirection(Vector3.forward)

it didn't work though, thanks for your help, I appreciate it.

Show more comments

Follow this Question

Answers Answers and Comments

122 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

Related Questions

Raycast returns null for no apparent reason 0 Answers

[help]RayCast check [SOLVED] 2 Answers

ScreenPointToRay ray not coming through from camera 0 Answers

Raycast not working 2 Answers

Can you figure out raycast origin position from RacyastHit? 2 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