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 /
This question was closed May 15, 2015 at 11:37 PM by Baste for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by BDX777 · May 14, 2015 at 06:26 AM · playervectorworldspacemomentumlocalspace

WorldSpace movement?

Hi, I'm trying to convert a vector for local space movement to a World Space vector for movement. Let's say I jump and I will move in the direction I jumped, except the problem is it is local space and relative to camera rotation and you will move relative to the camera, which is both right and wrong.

I'm trying to make it so you move in the direction you are facing, but when you jump in that direction, you'll turn around and you will still be going in the direction you were originally looking instead of always moving relative to the camera.

So I believe the solution to this is to have a world space vector and a local space vector, local space for inputs (So X is sidestep and Z is forward/backpedal, Y being vertical gravity and such) and the world space vector which takes the local space information, converts it to world space, and then treats them as accumulative values to simulate momentum with the CharacterController.Move method.

I've tried transform.TransformPoint, but my character floats towards the ceiling and then falls back down for a bounce. There must be some way to do this.. Any ideas?

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

  • Sort: 
avatar image
1

Answer by Baste · May 14, 2015 at 08:20 AM

The world space forward vector is transform.forward. You also have transform.up, transform.left, transform.right, etc.

So when you jump, you store the current transform.forward (or the current movement input) as the jump direction vector, and use that for motion while in the air, never changing it before you land.

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 BDX777 · May 14, 2015 at 10:35 AM 0
Share

Yes but what about other things such as sliding in puddles and getting knocked back by explosions? Could this all be handled by a secondary vector that is for world space? $$anonymous$$y input vector is the character's rotation multiplied by the same vector, does that count as local space? I think it does, please correct me if I'm wrong.

avatar image Baste · May 14, 2015 at 03:08 PM 1
Share

The same technique can be used for everything that's supposed to lock your movement in a direction. Assu$$anonymous$$g that you've got some method $$anonymous$$ove that moves your character, then it'd look something like this:

 bool directionLocked = false;
 Vector3 lockedDirection;

 //or in FixedUpdate, depending on how you move.
 void Update() {
     if(directionLocked) {
         $$anonymous$$ove(lockedDirection);
     }
     else {
         $$anonymous$$ove(transform.rotation * inputVector);
     }
 }

And then whenever you jump, start sliding, or start getting knocked back, you call a method somewhat like this:

 void Lock$$anonymous$$ovementInDirection(Vector3 dir) {
     directionLocked = true;
     lockedDirection = dir;
 }

So jumping would look like this:

 void Jump() {
     Lock$$anonymous$$ovementInDirection(transform.forward);
     //Handle other jumping stuff, like a coroutine that moves the character on the y-axis or whatever
 }

and so on. Whenever you should stop having your direction locked - when you detect that you land, or when the knockback is over - just set directionLocked to false again.

avatar image BDX777 · May 15, 2015 at 01:09 AM 0
Share

Hmmm I'll test this out. From the looks of this, this will disable your movement until you either land or slide out of a water puddle. Isn't there something where I can just move in the locked direction and simply add to it's values with an input vector? I want to give players some air control. $$anonymous$$inda like the way some old PC games have player momentum, like running and jumping in Half Life.

avatar image Baste · May 15, 2015 at 07:32 AM 1
Share

In that case, whenever your movement is locked, you lerp from the old movement to the new movement rather than setting it directly.

avatar image BDX777 · May 15, 2015 at 07:28 PM 0
Share

Yep I remember trying something like that before, but not with a movement lock boolean or while jumping. It works btw, it works great.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

rigidbody.MoveRotation neither world space or local? How does it work? 1 Answer

Box Collider Vertexes in World Space 3 Answers

Raycasting, How to draw a line to the position of the rays end when nothing is hit 1 Answer

How do I get the world space up direction for RotateAround? 0 Answers

vertices to world 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