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 WhipJr · Apr 24, 2017 at 06:19 PM · rotationmovementplayerquaternion

can anyone find the issue with this code?

this code is called as the player is wall running, it turns the player as the normal they are attached too changes for use on round surfaces. the issue is /not/ in the "_left" portion, that works entirely as expected. the issue is when the player tries to run around a curved surface on the right side. the player does not rotate, aside from the initial rotation on impact with the surface which uses the same exact rotation code, the difference being that this is in update so it happens for the duration of the wallrun.

 if (_wallRunning)
         {
             if (_left)
             {
                 Debug.Log("left");
                 RaycastHit hit;
                 Ray ray = new Ray(transform.position,-transform.right);
                 if (Physics.Raycast(ray, out hit))
                 {
                     transform.rotation = Quaternion.FromToRotation(Vector3.right, hit.normal);
                 }
             }
             else if (_right)
             {
                 Debug.Log("right");
                 RaycastHit hit;
                 Ray ray = new Ray(transform.position, transform.right);
                 Debug.DrawRay(transform.position, transform.right, Color.red); //draws ray being cast
                 Debug.Log(Physics.Raycast(ray, out hit));//returns true
                 if (Physics.Raycast(ray, out hit))
                 {
                     Debug.Log(transform.rotation);//check rotation
                     transform.rotation = Quaternion.FromToRotation(-Vector3.right, hit.normal);
                     Debug.Log(transform.rotation);//no change
 
                 }
 
             }
         }

Here is a link to a (very bad) video showing the problem on youtube.

also: alt text this has my current hierarchy and the script attached to the player

unity-problem2.jpg (242.6 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

2 Replies

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

Answer by Bunny83 · Apr 25, 2017 at 08:59 AM

Well, have you made sure that:

  • "_right" is true all the time while you wall run? Where and how is it set to true? In short: are you sure your code actually runs every frame?

  • You should limit your raycast length. Otherwise you could "wallrun" a wall that's 100m away to your right / left

  • Are you sure the object your raycast hits is actually the wall? Maybe you hit something on your player?

When using Debug.Log you should always add some description to be able to identify which log comes from which line in code.

 Debug.Log("R object hit: " + hit.gameObject.name);
 Debug.DrawRay(hit.point, hit.normal, Color.yellow); // vizualize hit point and hit normal
 Debug.Log("R old rotation: " + transform.eulerAngles);
 transform.rotation = Quaternion.FromToRotation(-Vector3.right, hit.normal);
 Debug.Log("R new rotation: " + transform.eulerAngles);

 

Note that i prefixed the messages with "R" so we know those come from the "right" part and not the "left". Seeing what you actually hit and where should help finding out what's wrong.

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 WhipJr · Apr 25, 2017 at 02:40 PM 0
Share

okay, so the issuw was that the raycast appeared to be hitting the wall, but it was getting the hit information from a trigger i had on the player ins$$anonymous$$d. thank you for pointing me in the direction i needed to fix this issue.

I fixed this issue by going to:

Edit > Project Settings > Physics > Uncheck "Queries Hit Triggers"

avatar image
0

Answer by tanoshimi · Apr 24, 2017 at 07:13 PM

Trying to understand your logic, but on lines 10 and 23, did you not mean:

 transform.rotation = Quaternion.FromToRotation(transform.right, hit.normal);

and

 transform.rotation = Quaternion.FromToRotation(-transform.right, hit.normal);

?

Comment
Add comment · Show 5 · 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 WhipJr · Apr 24, 2017 at 07:22 PM 0
Share

at first i thought the same thing, however upon changing Vector3 to transform, it causes the player to be angled to the world.right ins$$anonymous$$d of the local.right for some reason.

avatar image tanoshimi WhipJr · Apr 24, 2017 at 07:51 PM 0
Share

That sounds odd. Your objext isn't parented to another object which has been rotated, has it?

avatar image WhipJr tanoshimi · Apr 24, 2017 at 07:56 PM 0
Share

nope, this is directly attached to the player which isnt a child of anything. This is a video link to youtube to show you exactly what is happening with the code above. please take note that when i jump to the walls on the right side, everything snaps the players rotation as it should, until it needs to rotate the player on the right side curve.

Show more comments

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

Animator movement and mouse position problem 0 Answers

How can I move an object to click point in 2D? 0 Answers

Why my player don't go forward? 0 Answers

Gradual Rotation of Character from 2 Axis Input Sources 0 Answers

Rotating an object to target on the Z axis 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