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 rubenpvargas · May 22, 2012 at 02:58 AM · vector3directionrelative

Obtain direction from a point relative to another point

First, srry for bad english isnt my primary lenguaje

im having trouble trying to get the direction of a vector 3 point.

i have touchphase and a raycast, so i want to take the point of touch and make my character jump in that direction. Everything is working fine, but my character jump in a diferent direction.

i think it is happen because the direction is based on the 0,0,0 point,

what i need to do to make the direction relative to the current character position?

thanks

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

3 Replies

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

Answer by Berenger · May 22, 2012 at 04:25 AM

For the basics, the vector from A to B is B - A. For something more pratical, see aldonaletto's answer.

Comment
Add comment · Show 3 · 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 rubenpvargas · May 22, 2012 at 05:35 PM 0
Share

actually, im making a 2d game, this is why i cant use lookat, i will try substract the points, thanks a lot

avatar image rubenpvargas · May 22, 2012 at 05:57 PM 0
Share

this just wor fine, im now hitting my head asking myself why i dont think in this before, thanks a lot :)

avatar image Berenger · May 22, 2012 at 07:34 PM 0
Share

I won't lie to you, I'm not really the first to think about vector calculation :p

avatar image
0

Answer by Unk · May 22, 2012 at 04:33 AM

Assuming you are in a top down view and you want your character to move/jump in the direction you touched I would first make the character look at the spot touch using transform.LookAt(touchedPosition); and then you can move your character using on his Vector3.forward..

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
avatar image
0

Answer by aldonaletto · May 22, 2012 at 04:01 AM

The question is too vague - you should post your script.
Anyway, in most cases you should do something like this:

function Update (){
  if (Input.touchCount > 0){
    var touch: Touch = Input.touches[0];
    if (touch.phase == TouchPhase.Began){
      var ray = Camera.main.ScreenPointToRay (touch.position); // get a ray from the touch
      var hit: RaycastHit;
      if (Physics.Raycast(ray, hit)){ // if the ray hits something...
        // hit.point contains the 3D point clicked
        // jump to this point
      }
    }
  }
}
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 rubenpvargas · May 22, 2012 at 05:37 PM 0
Share

i didnt post the code, because i dont need that stuff, mi code is ok, i only need the method to obtain the correct direction. Thanks anyway

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

7 People are following this question.

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

Related Questions

What is a way to use a value and return it back to zero? 1 Answer

How to get object to face direction it's flying rather than looking at the target 2 Answers

How can I move character controller in one direction 0 Answers

teleport player in the direction they are looking, 1 Answer

Calculate vector exactly between 2 vectors 4 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