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 20, 2011 at 02:21 PM · javascriptraycastraycastingdiagonal

Raycast help.....

Hi,

I was wondering how or if you can cast a diagonal ray in unity. see in my game one of the players weapons is a shotgun and i wanted to cast 3 rays from the player eg. one going straight forward and one on either side going around 45 degrees. is this possible ? how would i do it ? could i cast a ray from point A to point B with both Point A and B having a (x,y,z) location? code would be great thanks :)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Joshua · Apr 20, 2011 at 02:30 PM

Read up on the documentation on raycasting..

Comment
Add comment · Show 1 · 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 21, 2011 at 12:39 AM 0
Share

:) thanks heaps

avatar image
0

Answer by Chris 35 · Apr 21, 2011 at 01:00 AM

i was wondering why this code doesn't work ? i want to just cast a ray and what ever it hits returns a print statement is my Debug.Draw ray correct ?

var xDirection = 15;

var yDirection = 0; var zDirection = 45; var length = 0.1; var hit : RaycastHit;

function Update () { var diagonal = transform.TransformDirection (Vector3(xDirection,yDirection,zDirection)); Debug.DrawRay(transform.position, diagonal * length,Color.green);

if (Physics.Raycast (transform.position, diagonal,hit,length)) {
    print ("There is something in front of the object!");
}

}

help please

thanks

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 Joshua · Apr 21, 2011 at 01:45 AM 0
Share

The "diagonal = transform.TransforumDirection" makes no sence to me. Just say "diagonal = Vector3(xDirection,....)" I think.

avatar image Chris 35 · Apr 21, 2011 at 02:06 AM 0
Share

the transform.TransformDirection means that the ray will rotate with my character, because my player faces the direction of the mouse it needs that code so the ray follows. i still cant get it to detect the collision of the ray and an object tho

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

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

Raycasting problems 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