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 Mar 25, 2014 at 08:44 AM by Fattie for the following reason:

Duplicate Question

avatar image
0
Question by AnomalousX12 · Mar 25, 2014 at 06:53 AM · velocitydirectionside-scrollinglocal velocity

How can I get the velocity of an object in relation to the world?

All I can find are local velocity questions. Well I've been using

 transform.InverseTransformDirection(rigidbody.velocity);

in my player's script to make my camera adjust its speeds according to the player.

Then I've been using

     void Update () 
     {
         xPosition = player.transform.position.x;
         yPosition = player.transform.position.y + 5f;
         zPosition = player.transform.position.z - 14f;
         xPosMulti = 1f + (playerScript.playerVel.x * 0.0001f);
         yPosMulti = 1f + (playerScript.playerVel.y * 0.0001f);
         zPosMulti = 1f + (player.rigidbody.velocity.magnitude * 0.01f);
 
         transform.position = new Vector3(xPosition * xPosMulti, yPosition * yPosMulti, zPosition * zPosMulti);
 
     }

in my camera. It works really well, even if it's a little too jumpy for me (Any way to make it feel more springy?), except that it "Looks" the wrong way when my player (Which is just a cube) is upside down. I want to cube to be able to rotate, so locking its z rotation isn't an option.

Further details: It's a side-scrolling game with a cube as a player. The camera follows the cube and when the cube goes faster, the camera looks further in that direction. Unfortunately, when the cube is upside-down, the camera looks backward instead of forward. I assume this is because my "transform.Inverse etc" line is measuring the velocity of my player in relation to its direction, not the direction in the world. How do I fix this?

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 fafase · Mar 25, 2014 at 07:00 AM 0
Share

You could use the SmoothFollowCamera script from Standard Assets

avatar image AnomalousX12 · Mar 25, 2014 at 07:02 AM 0
Share

Awesome!! Thank you! I'll check that out.

avatar image AnomalousX12 · Mar 25, 2014 at 05:14 PM 0
Share

That doesn't seem to work very well with my game. Anything but max or nonexistent height damping makes the camera shake and it doesn't help going left or right at all since I'm sliding and not rotating.

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by AnomalousX12 · Mar 25, 2014 at 06:59 AM

Just don't use "transform.InverseTransformDirection." Make it only "rigidbody.velocity."

Comment
Add comment · 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

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

Final direction and velocity of two velocities [World Velocity and Local Velocity] 0 Answers

Rigidbody Local Velocity 1 Answer

Moving a ball in the opposite direction of where it hits 1 Answer

Rotation and Velocity of bullets. 1 Answer

Un-normalize direction 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