• 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 NovaDrox · Oct 10, 2018 at 04:29 PM · rigidbodyvelocitymomentum

Continuing the momentum of the rigidbody

So, I have a basic cube with a rigidbody on it. Then I created a grapple hook script that uses a line to represent that line between the point it hits and the player. I got it to the point where the player does go to the spot of the point that was hit, but if I stop the grapple mid air, it stops all moment of the cube and it just drops straight down to the platform below it. I want to be able to continue that momentum of the cube so it moves forward as it still drops.

Script:

 private void Movement()
 {
     float distance = Vector2.Distance(lineRen.GetPosition(1), hit.point);

     if (hitObject)
     {
         if (distance < 1)
         {
             Vector3 movePath = (transform.position - hit.point).normalized;

             RB.MovePosition(RB.position + movePath * Time.deltaTime * -pullStrength);
         }
     }
     else
     {

         RB.velocity = RB.velocity;
     }
 }
 private void SingleGrapple()
 {
     ray = Camera.main.ScreenPointToRay(Input.mousePosition);

     if (clickReady)
     {
         if ((Input.GetMouseButtonDown(0)))
         {
             if (Physics.Raycast(ray, out hit))
             {
                 lineRen.SetPosition(1, transform.position);
                 hitObject = true;
                 clickReady = false;
             }
         }
     }

     if (hitObject)
     {
         lineRen.SetPosition(0, transform.position);

         Vector3 newPos = Vector3.MoveTowards(lineRen.GetPosition(1), hit.point, Time.deltaTime * travelSpeed);

         lineRen.SetPosition(1, newPos);

         RB.useGravity = false;
     }
 }
Comment
Add comment · Show 2
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 TreyH · Oct 10, 2018 at 04:36 PM 0
Share

There doesn't seem to be anything here indicating what changes when your grapple is "cancelled". Also, this block is pretty useless:

 else
 {
     RB.velocity = RB.velocity;
 }


Where are you cancelling the grapple and how does that influence these values?

avatar image NovaDrox TreyH · Oct 11, 2018 at 02:47 PM 0
Share

The RB.velocity thing was something I forgot to get rid of. As for when it cancels, I have in the $$anonymous$$ovement() method is that it detects the distance between the the point the ray hits on an object and the position of the line end. I have set a bool to disable the ray part so the line goes to one point, and that is part of SingleGrapple() method. once the line end meets the hit point of the ray, it then does the $$anonymous$$ovement() method to pull the cube towards the point the line is. I have a if statement checking the input of $$anonymous$$ouse(0) to see if it is up, which then re-activates the ray firing trigger and disables the movement of the cube from going to the point.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

123 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 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

Can i make more gripped rigidbody sphere Controllers 0 Answers

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

Is it possible to increase stopping distance with forcemode.velocitychange? 0 Answers

rigidbody.velocity.normalized application 1 Answer

Is there a way to set velocity while setting the position? 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