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 ketain · Nov 28, 2013 at 05:23 PM · charactercontrollersplinecharactermotormovment

Move in look direction with PlayerController

Hello,

I have a character that moves on a splinebased path. I have a method that calculates my look rotation based on my current position on the path (I get a point that is just before me on the path. So i am able to always look in the direction i am heading).

Is it possible to use the CharacterController / CharacterMotor to move in the direction i am looking? My look rotation is updated in every update cycle. So the movment direction must be adjusted every frame as well. I have tried this before by myself but got really weird results.

Here is the code for the recalculation of the rotation. (There is code used from the iTween examples mixed with my own code and method calls from whydoidoit´s Splinemovement):

 /*
  * pathPosition = percentage my character already travelled on the path
  * lookAheadAmount = the percentage i want to add every cycle to my current pathPosition
  *                      (how far i want to look ahead as a percentage)
  * lookPercentage = combination of lookAheadAmount and pathPosition thus 
  *                      the percentage of the point that i want to look at
  * 
  * lookTarget = a Vector3. Its the point before me i want to look at
  */
 private void FindRotation ()
 {
     float lookPercentage;
     //calculate look data if we aren't going to be looking beyond the extents of the path:
         
     //leading or trailing point so we can have something to look at:
     if (pathPosition + lookAheadAmount <= 1 && characterDirection == Direction.Forward) {    
         //if i walk forward I need to add the lookAheadAmount
         lookPercentage = pathPosition + lookAheadAmount;
         //MoveOnPath transforms my percentage into a Vector3
         lookTarget = Spline.MoveOnPath (path, transform.position, ref lookPercentage,maxPlayerSpeed, globalSmooth, EasingType.Linear, false, false);
         transform.LookAt (lookTarget);
         
         //nullify all rotations but y since we just want to look where we are going:
         float yRot = transform.eulerAngles.y;
         transform.eulerAngles = new Vector3 (0, yRot, 0);
     }        
     if (pathPosition - lookAheadAmount >= 0 && characterDirection == Direction.Reverse) {
         // if i move backwards i need to substract my lookAhead amount
         lookPercentage = pathPosition - lookAheadAmount;
         
         //MoveOnPath transforms my percentage into a Vector3
         lookTarget = Spline.MoveOnPath (path, transform.position, ref lookPercentage,maxPlayerSpeed, globalSmooth, EasingType.Linear, false, false);
             
         transform.LookAt (lookTarget);
         
         //nullify all rotations but y since we just want to look where we are going:
         float yRot = transform.eulerAngles.y;
         transform.eulerAngles = new Vector3 (0, yRot, 0);
     }
 }

It would be awesome if I could use the character controller/ charactermotor because I must not worry about collisions, jumping and sliding.

Comment
Add comment · Show 3
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 Fornoreason1000 · Nov 28, 2013 at 05:48 PM 0
Share

you don' t need character motor , but you can use third person controller. and its camera, it rotates the Vector3.fwd property of the player then use input to move in that direction, it will then rotates the player to move the way.

avatar image ketain · Nov 28, 2013 at 09:41 PM 0
Share

I am currently trying to do what you said. If the question is not clear enough i will explain it further. :)

avatar image robertbu · Nov 28, 2013 at 10:39 PM 0
Share

We need to see the move code, not the rotation code to solve this problem.

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

17 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

Related Questions

Default Character Motor randomly jumping? 1 Answer

Spline with character enter 0 Answers

Character Motor won't go up stairs. 6 Answers

How to I make my player push off of the ground? 0 Answers

Moving platform option in new FPS controller 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