• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

How do I specify the origin and end points of the arc1 instantiated line? 0 Answers

I use RaycastHit and make other obj move to hit obj but obj move to center/pivot of hit obj not world Space 0 Answers

Make rotation of two objects match in Unity3D 1 Answer

Transform.up doesnt give me it´s local up position 1 Answer

Changing transform.localscale doesn't take affect immediately? The next RayCast isn't precise 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges