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 Chris 35 · Apr 22, 2011 at 04:21 AM · javascriptraycastraycastingnormalize

Raycasting problems

how come the Normalize() function wont work for more then one variable ? i cant see any error in my code.....

var Bullet1_direction = Vector3(15,0,45); var Bullet2_direction = Vector3(0 ,0,1); var Bullet3_direction = Vector3(1 ,0,0); var length = 4;

function Update () { var Bullet1_diagonal = transform.TransformDirection(Bullet1_direction); Bullet1_diagonal.Normalize();

var Bullet2_diagonal = transform.TransformDirection(Bullet2_direction); Bullet2_diagonal.Normalize();

var Bullet3_diagonal = transform.TransformDirection(Bullet3_direction); Bullet3_diagonal.Normalize();

Debug.DrawRay(transform.position, Bullet1_diagonal length,Color.green); Debug.DrawRay(transform.position, Bullet2_diagonal length,Color.red); Debug.DrawRay(transform.position, Bullet3_diagonal * length,Color.blue);

if (Physics.Raycast(transform.position, Bullet1_diagonal,length)) { Debug.Log ("Bullet 1 hit green!"); } if (Physics.Raycast(transform.position, Bullet2_diagonal,length)) { Debug.Log ("Bullet 2 hit red!"); } if (Physics.Raycast(transform.position, Bullet3_diagonal,length)) { Debug.Log ("Bullet 3 hit blue!"); }

}

any help would be great

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 burgunfaust · Apr 22, 2011 at 04:35 AM

From the script reference:

If this vector is too small to be normalized it will be set to zero.

Normalize proportionally changes the vector to a 0 to 1 range, so

var Bullet1_direction = Vector3(15,0,45);

becomes (0.3,0.0,0.9)

var Bullet2_direction = Vector3(0 ,0,1);

becomes (0,0,1)

var Bullet3_direction = Vector3(1 ,0,0);

Becomes (1,0,0)

No change to the last two vectors, because they are already within the range in question.

Comment
Add comment · Show 2 · 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 Chris 35 · Apr 22, 2011 at 05:41 AM 0
Share

could you show my error in relation to my code ?

avatar image burgunfaust · Apr 22, 2011 at 12:36 PM 0
Share

What are you trying to do with this script exactly?

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

No one has followed this question yet.

Related Questions

Raycast help..... 2 Answers

Turret that shots a raycast to detect my character then shots at him. 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

ray cast not working ? 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