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 /
  • Help Room /
avatar image
0
Question by DedValve · Jul 05, 2016 at 05:56 PM · raycasttransformtransformpoint

Have Raycast rotate on local position with fixed direction

I've asked this problem before with little help a few weeks ago so I decided to rebuild what I wrote from scratch to see if I could resolve the problem.

I want to be able to have a raycast at a fixed position in front of my players at all time for things such as determining which ledges to climb.

Here is a gif to demonstrate the effect I want to achieve: http://imgur.com/a/dh2x9

The top gif is what I want, for it to remain in front of my player at all times. When I begin to move the raycast stretches and moves around my player rather than stay in front.

I think it could be my movement code (which is for now just a copy/paste of Unity's character controller) or my raycast code.

Here is my raycast code:

     public Vector3 lHandVectorOrigin = new Vector3(0, 2, 1); 
     public Vector3 lHandVectorDir = new Vector3(-0.5f, 0f, 0f);
 
     void FixedUpdate () {
         RaycastHit lHit;
         if (Physics.Raycast (transform.TransformPoint (transform.localPosition + lHandVectorOrigin), transform.TransformPoint (-Vector3.up + lHandVectorDir), out lHit, 1f)){
         }
     }
 
     void Update () {
         Debug.DrawRay (transform.TransformPoint (transform.localPosition + lHandVectorOrigin), transform.TransformPoint (-Vector3.up + lHandVectorDir), Color.red);
     }

And for my movement code I just copy/pasted what was here for a quick job: https://docs.unity3d.com/ScriptReference/CharacterController.Move.html Specifically I think this line may have something to do with my raycast not behaving properly:

             moveDirection = transform.TransformDirection(moveDirection);
 

Interestingly when I added a rigidbody or edited my move code the behavior didn't change at all which makes me wonder if the problem is simply in my raycast code.

At the end I'm not even sure if this is the proper way to determine ledges and grabbing so if there are any alternatives I'd gladly listen to those too!

Comment
Add comment · Show 1
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 DedValve · Jul 06, 2016 at 03:13 PM 0
Share

Would Quaternion.eulerAngles be a good place to start? I know very little about Quaternion

0 Replies

· Add your reply
  • Sort: 

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

62 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

Related Questions

Find Script and call function FROM hit.transform 0 Answers

DESPERATE How to align transform.up with another vector3 (direction) ? 1 Answer

Multiple game objects same script 0 Answers

Ray cast to object to transform, instead all objects with script transform. 0 Answers

Trying to match two objects rotations smoothly. 0 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