Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 GhostNighto · Jul 18, 2019 at 07:36 PM · vector3.movetowards

Vector3.MoveTowards moving away from target position

Hi, I have an issue with MoveTowards actually moving away from the target and I don't understand why this is happening. I have a player object (Self) that uses Raycast to get the GrapplingPosition (hit.point) to get a position on a terrain. When I use the following code, the Self object starts moving away from the GrapplingPosition instead of moving toward it. I have attached my Debug.log code below to show what is going on. I tried to use the same code toward random directions and they all do the same move away behavior. Can someone help explaining why this is happening?

 Self.transform.position = Vector3.MoveTowards(Self.transform.position, GrapplingPosition, PullSpeed * Time.deltaTime);
 Distance = Vector3.Distance(Self.transform.position, GrapplingPosition);
 Debug.Log("Self: " + Self.transform.position + ", Distance: " + Distance + ", Target: " + GrapplingPosition);

 Self: (491.5, 136.0, 202.7), Distance: 29.96443, Target: (464.7, 140.6, 215.2)
 UnityEngine.Debug:Log(Object)
 GrapplingHook:Update() (at Assets/Scripts/GrapplingHook.cs:52)
 Self: (491.7, 136.0, 202.6), Distance: 30.12826, Target: (464.7, 140.6, 215.2)
 UnityEngine.Debug:Log(Object)
 GrapplingHook:Update() (at Assets/Scripts/GrapplingHook.cs:52)
 Self: (491.8, 136.0, 202.6), Distance: 30.27597, Target: (464.7, 140.6, 215.2)
 UnityEngine.Debug:Log(Object)
 GrapplingHook:Update() (at Assets/Scripts/GrapplingHook.cs:52)


Update with additional information: Hi, I just want to add a little bit more information. If I use a negative PullSpeed then this code works fine toward to position I point with my Raycast. What I don't understand is why it needs to be a negative in this case. I also tried to do a DrawRay and it is connecting the two positions correctly.

Comment
Add comment · Show 4
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 Vega4Life · Jul 18, 2019 at 07:47 PM 0
Share

Do this as a test: Run the script and get the logs, then pause the game. In the scene place a sphere object, then take the logs "Target position" and apply it to the sphere. It should move the sphere to where the GrapplingPosition is. Is the sphere where the player grappled?


I suspect, the grappling position isn't where you think it is. Thus the move towards is going the wrong way.

avatar image ryanmillerca · Jul 18, 2019 at 07:56 PM 0
Share

Do you have visual confirmation that the Self is actually moving away? The distance could be reportedly going up because of your terrain traversal (going up a hill in the direction of the target could still increase distance, if it's steep). I'm willing to bet this is collision/rigidbody related.

avatar image CCnockaert · Jul 18, 2019 at 08:06 PM 0
Share

Use Gizmos to draw a line from your Self gameobject to the GrapplingPosition, I think your RaycastHit point isn't where you think it is.

avatar image CCnockaert CCnockaert · Jul 18, 2019 at 08:27 PM 0
Share

Well, maybe your PullSpeed is negative ?

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Vector3.MoveTowards MaxDistanceDelta value 2 Answers

I'm getting some very strange movements from an object position 1 Answer

Unexpected behavior on Vector3.moveTowards for Player 0 Answers

Vector2.MoveTowards problem 0 Answers

Using collision with Vector3.MoveTowards 3 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