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 corax · Sep 25, 2012 at 02:02 PM · vector3distance

Fixed distance from point

Hi,

I need to generate a point from another fixed point that has a fixed distance. The point must be the closer point to the player. So If I have a start point 0,0,0 the nearest point to the player that is 10 feet distant from 0,0,0.

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 Paulo-Henrique025 · Sep 25, 2012 at 02:10 PM 0
Share

You want a point that is aways 10 feet forward the player?

avatar image corax · Sep 25, 2012 at 02:11 PM 0
Share

10feet from the starting point (0,0,0)

avatar image Paulo-Henrique025 · Sep 25, 2012 at 02:14 PM 0
Share

Add your comment as an answer @Fattie

1 Reply

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

Answer by Zerot · Sep 25, 2012 at 02:19 PM

let's say point a is the origin, point b is the player and d is the distance you want.

Then the resulting point is p = a+(b-a).normalized*d

(b-a).normalized should return a vector that is the direction from a towards point b. we normalize it to make it length 1.

We multiply it with d so it gets the right length. And we add it to point a because we want its position to be relative to a.

Comment
Add comment · Show 6 · 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 Fattie · Sep 25, 2012 at 02:20 PM 0
Share

hey you're right ... I think that's what he's asking

Good one.

avatar image corax · Sep 25, 2012 at 02:30 PM 0
Share

Nice one man this works :D the only problem that my dist must be negative to be on the right side (near the player). If "d" is positive the point is correctly aligned with the character but on the other side of the starting point :D

avatar image Zerot · Sep 25, 2012 at 02:36 PM 1
Share

Ah, my mistake. It should be b-a ins$$anonymous$$d of a-b.

avatar image corax · Sep 25, 2012 at 02:38 PM 0
Share

Can you edit? so for the other guys that will see this answer :D

avatar image Zerot · Sep 25, 2012 at 02:40 PM 1
Share

Fixed it :)

Show more comments

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

11 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

Related Questions

Distance won't work 1 Answer

Distance between a point and any point on an object 0 Answers

Interact with objects based on distance. 1 Answer

Vector3.Lerp - Constant speed between distance changes 3 Answers

Move parent so children align with other obj! 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