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 Antao98 · Feb 19, 2019 at 11:23 PM · raycastingworldspacelocalscaleclimbing

Keeping raycast position and rotation equal as gameObject

Hello,

I'm currently making a climbing system from scratch and am having some problems with the raycasts. I have two raycasts shooting diagonally from a bit up and to the front of my character. My problem is that when I rotate my character the raycast origin point 'z' coordinate stays the same.

I have tried the transform.TransformDirection method and it actually gets worse. The only solution I could think of right now was to create an empty gameObject and child it to the character and getting its position through the inspector, but there's got to be a way...

The raycasts are the blue lines in the images, I also have a link to a gif so you can understand clearly what the problem is.

 Debug.DrawRay(transform.position + Vector3.up * 1f + Vector3.forward * .3f, transform.TransformDirection(new Vector3(1f, -1.5f, 0)) * 1.5f, Color.blue); 
         Debug.DrawRay(transform.position + Vector3.up * 1f + Vector3.forward * .3f, transform.TransformDirection(new Vector3(-1f, -1.5f, 0)) * 1.5f, Color.blue); 
 

GIF: https://gph.is/g/Z5Y19BZ

alt text alt text

help1.png (71.3 kB)
help3.png (62.5 kB)
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
Best Answer

Answer by jstopyraIGG · Feb 20, 2019 at 12:25 AM

Use transform.forward instead of Vector3.forward. Vector3.forward is 1 unit forward in world space (always {0, 0, 1}), transform.forward is 1 unity forward in local space, which depends on your objects rotation. The TransformDirection stuff is in world space as well, and you should do local space.

 //get a vector half way between left and forward.
 Vector3 leftDir = Vector3.Lerp(transform.forward, -transform.right, 0.5f);
 //-1.5f how much far down.
 leftDir.y = -1.5f;

 Vector3 rightDir = Vector3.Lerp(transform.forward, transform.right, 0.5f);
 rightDir.y = -1.5f;

 Debug.DrawRay(transform.position + Vector3.up * 1f + transform.forward * .3f, leftDir.normalized * 
 1.5f, Color.blue); 

 Debug.DrawRay(transform.position + Vector3.up * 1f + transform.forward * .3f, rightDir.normalized * 
 1.5f, Color.blue); 

Try this, I have not tested this, but this should create ray going from above your head, diagonally down in front of you.

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 Antao98 · Feb 20, 2019 at 11:36 AM 0
Share

This is it! Thank you so much!

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

104 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

Related Questions

How to get the intersection point between a UI WorldSpace with a Raycast from a Gazer ? 0 Answers

from world to local coordinates bouncing ball? 1 Answer

How to get 3D worldspace position from 2D touch/mouse position 3 Answers

Using World Space, how would I bring up info on click. 0 Answers

Scale object based on another object's position 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