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 Chaos-Fusion · Jul 23, 2020 at 04:42 AM · vector3velocitydirectionaxisteleporting

Get Direction based on Velocity

Currently, I'm working on a type of teleportation for my FPS and I've gotten it to preserve the local position and rotation of the player based on where you are on the object. alt text

However, after teleporting and if the player releases the movement button, the players remaining velocity won't adjust to the local rotation so it continues in it's original direction. like so: alt text Currently, this is how the player velocity is calculated:

 MovementVector = (((directionIntentY * zSaved) + (directionIntentX * xSaved)) * TotalSpeed);

The directionIntentY and X are the Camera direction, Total Speed is the movement speed and xSaved+zSaved are the movement axis retrieved from the input.

 x = Input.GetAxis("Horizontal");
 z = Input.GetAxis("Vertical");
 
 if (movement button is being held)
 {
     xSaved = x;
     zSaved = z;
 }

Originally, I was adjusting the Camera look position during the teleport to preserve the direction which at first glance works however If the player changes where they are looking before teleporting, their velocity direction will change after teleporting based on their velocity and where they were looking. All I want is the original velocity direction to be preserved.

 //PlayerMove is just a reference to the player object.
 PlayerMove.directionIntentX = PlayerMove.Camera.right;
 PlayerMove.directionIntentX.y = 0;
 PlayerMove.directionIntentX.Normalize();
 
 PlayerMove.directionIntentY = PlayerMove.Camera.forward;
 PlayerMove.directionIntentY.y = 0;
 PlayerMove.directionIntentY.Normalize();


Looking deeper into the issue, I'm hoping I can solve the issue via the xSaved & zSaved variable since those 2 variables control the direction of the movement. I'm hoping by changing those variables to match the new direction, the velocity direction will match up with the local velocity direction of the teleporter.

From the Teleport Object script, I tried using the movement vector, Camera direction, transform.forward to get the appropriate normalised direction:

 Vector3 DirNorm =transform.InverseTransformDirection(PlayerMove.MovementVector).normalized;
 //PlayerMove is just a reference to the player object.
 PlayerMove.xSaved = DirNorm.x;
 PlayerMove.zSaved = DirNorm.z;

However none of the vector3 values I got matched up with the intended direction I can avoid this issue by ensuring all teleporters share the same rotation however I just want to allow some creativity with their placement so what can I do?

direction-2.png (2.7 kB)
direction.png (4.3 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

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

161 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 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

teleport player in the direction they are looking, 1 Answer

Find a Position on the Axis of a GameObject 1 Answer

How to prevent movement in a specific direction only? -1 Answers

Issue regarding Rigidbody2D 0 Answers

Character Controller Movement - Different speeds on different 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