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 gumboots · Jul 29, 2012 at 01:06 PM · vector3jumplerptranslatetransformdirection

Lerp jump using input won't convert to world space

Hi there,

When I jump in a direction, the character jumps relative to itself, rather than the camera I'm looking through. Explained properly below:


My jump function applies jump force like so:

 target.Translate(Vector3.Lerp(from, to, elapsed / time) * DeltaTime);

Which is triggered when I press the jump button, however the character jumps according to its local direction, of the camera based directional input. Those values are all fed from the code below, 'from' and 'to' are sent from the MovementInput Vector, Elapsed is calculated when the jump function begins and Time is how long the jump should take. DeltaTime is just a variable for Time.deltaTime. The jump works fine when 'from' and 'to' are Vector3.zero (Making the player jump straight up), but I can't get the directional jump working.

 //'test' is the code I tried 'TransformDirection' on, and just replaced 'MovementInput' with it
 
 Vector3 test = Camera.main.transform.TransformDirection(MovementInput);
 
 test.y = 0;
 
 Jump(MovementInput.normalized * 10f, MovementInput.normalized * 10f, jumpTime);

If I'm holding 'right', the character runs to the right of the screen, but if I press jump and the character jumps to its right (toward the camera) rather than jumping to the right of the screen (its forward). I've tried converting the MovementInput (Which is just horizontal and vertical input on the x and z axis) to the camera's transform direction, but that makes the character jump in directions I can't even explain.

I assume I must be doing something wrong with the TransformDirection. I use the exact same Vector3 to move the character according to the camera's direction:

 target.Translate(MovementInput * movementDistance, Camera.main.transform);

Any and all help appreciated.

Comment
Add comment · Show 5
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 Seth-Bergman · Jul 29, 2012 at 01:17 PM 0
Share

the question is, what is "f.From" and "f.To"?

avatar image Kryptos · Jul 29, 2012 at 04:05 PM 0
Share

And what are "f.Elapsed", "f.Time" and "DeltaTime"?

avatar image gumboots · Jul 29, 2012 at 11:20 PM 0
Share

Ah my apologies, that's probably not very clear. Those values are all fed when I run the jump function from the input code I'd provided, I just reworded the question so that it makes more sense. Thanks for pointing that out.

avatar image Seth-Bergman · Jul 30, 2012 at 10:23 AM 0
Share

but what we need to know is how those values are being reached.. the problem is mainly based in how you are reaching the value used for "to"

avatar image gumboots · Jul 30, 2012 at 11:00 AM 0
Share

Hi Seth, apologies again, I thought I cleared that up but obviously didn't! The '$$anonymous$$ovementInput' X and Z Vector is set by getting the horizontal and vertical axis, then they're sent in the 'Jump' function in the block of code above. However $$anonymous$$ike is spot on, and I can't believe I didn't read the 'Translate' page properly! Thanks for your help.

1 Reply

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

Answer by whydoidoit · Jul 30, 2012 at 10:19 AM

Translate works in local coordinates unless you specify Space.world as the second parameter.

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 gumboots · Jul 30, 2012 at 11:01 AM 0
Share

Spot on, ashamed that I missed that! Thanks $$anonymous$$ike.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Vector3.Lerp moves in the wrong direction 1 Answer

Constant total time over multiple Lerp functions 4 Answers

vector3 lerp based on 2 different floats/axes? 1 Answer

Vector3.MoveTowards and Quaternion.RotateTowards 1 Answer

Simple script to move object doesn't work 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