Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 game-dev333 · Jul 13, 2015 at 01:16 PM · vector3direction

Direction between two point - add unit distance to player

i have a game which have two type of control one is joy stick and another is player will move towed your touch

 // FOR JOYSTICK
 Vector3 headingPosition = joystickpad.position - joystickController.position;
 float distance=  headingPosition.magnitude;
 Vector3 directtion = headingPosition / distance;
 additionValue = directtion * speed;
 player.transform.position -= additionValue;

 //FOR PLAYER FOLLOW TOUCH
 Vector3 headingPosition = player.transform.position - mousePosition;
 float distance=  headingPosition.magnitude;
 Vector3 directtion = headingPosition / distance;
 additionValue = directtion * speed;
 player.transform.position -= additionValue;

my player moves in right direction but the speed of both is difference. how can i make both the speed equal.

i have also tried with normalized but its not working

Comment
Add comment · Show 1
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 game-dev333 · Jul 13, 2015 at 02:21 PM 0
Share

at last i am adding that position to player position... this code is written in update..so when touch is detected distance will be calculated and additional value should be added to player position

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by TruffelsAndOranges · Jul 13, 2015 at 02:35 PM

Try this:

 // FOR JOYSTICK
  Vector3 headingPosition = joystickpad.position - joystickController.position;
  float distance=  headingPosition.magnitude;
  Vector3 directtion = headingPosition / distance;
  additionValue = directtion.normalized * speed;
  player.transform.position -= additionValue * Time.deltaTime;
  
  //FOR PLAYER FOLLOW TOUCH
  Vector3 headingPosition = player.transform.position - mousePosition;
  float distance=  headingPosition.magnitude;
  Vector3 directtion = headingPosition / distance;
  additionValue = directtion.normalized * speed;
  player.transform.position -= additionValue * Time.deltaTime;
Comment
Add comment · Show 4 · 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 game-dev333 · Jul 13, 2015 at 04:36 PM 0
Share

Thanks for replying. still there is huge difference between speed player movement by joystick and playermovement of touch touch is too fast than joystick, direction works fine

avatar image game-dev333 · Jul 13, 2015 at 05:24 PM 0
Share

I think this is because difference between touch and player is bigger then difference between joystick controller and joystick centre. any help?

avatar image TruffelsAndOranges · Jul 13, 2015 at 09:05 PM 0
Share

Since the direction is normalized there should be no difference in speed. It seems as if you either have a rigidbody that you are using wrong or that you have another script interfering with the movement.

You should place your transformation/physics code in FixedUpdate() and NOT Update().

avatar image game-dev333 · Jul 15, 2015 at 02:53 PM 0
Share

Thanks a lot ! It worked :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

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

Obtain direction from a point relative to another point 3 Answers

C# Raycast from Object direction (z-axis) + another Vector3 1 Answer

How can I move character controller in one direction 0 Answers

teleport player in the direction they are looking, 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