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 martin_cork · Aug 11, 2011 at 08:53 PM · c#gameobjectrigidbodyvelocity

C # Applying Velocity to Rigidbody

Hey all, I've got a bit of an issue here. I'm trying to add velocity to a gameObject so that after it has been moved it will just slowly come to a stop. I have to do it in C# and C# is a language that I dont have much experience with.

Below is the sample code that I'm using. Essentially, when the code inside "Input.GetMouseButtonUp(0)" is executed, I want velocity to be applied to the gameObject.rigidbody that has been moved.

 private Vector3 movement;
 
 
 protected GameObject pivot;
     
 public override void handleSingleTouch(iPhoneTouch touch) 
 {
     if (!allowDrag) return;

     movement = touchMovementVector(touch);

       this.startPivot(gameObject.transform.position); 
         pivot.transform.Translate(movement,Space.World);
      if (Input.GetMouseButtonUp(0)) {
         gameObject.rigidbody.velocity = new Vector3(0, 10, 0);
         }
         this.endPivot();            
  
         
 }
 

As it is, its moving the gameObject 10 for testing sake. Apologies if its something basic that I'm doing wrong, and I would appreciate any help. I have seen another question that is loosely related to my issue, but unfortunately it didnt help me much.

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 ungalyant2 · Sep 14, 2011 at 07:12 PM 0
Share

what do you actually want it to do? And what is it doing, I'm a bit hazy on the issue.

avatar image martin_cork · Sep 14, 2011 at 07:26 PM 0
Share

Hey unglyant, what I was trying to do at the time was to apply momentum to a rigidbody that had been manipulated/moved by the cursor. At the time I didnt know that the script 'DragRigidbody.js' was there to do exactly what I wanted to do, so I was barking up the wrong tree completely :s I must get a beginners guide to unity book so I can avoid asking silly questions like that again. Thanks for replying to my question too, I appreciate your help :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DoubleDouble · Aug 11, 2011 at 10:29 PM

I think you may be wanting to use a different function than velocity to slow something over time.

The script reference for velocity is here

If you read the description, it is more suited to an instant change of direction, while using something like AddForce or AddRelativeForce would be for repeatedly "pushing" something.

You may also want to take a look at SmoothDamp, it smoothly translates a number from the current value to a target value (you could set as 0?).

You can use the script reference for Unity for looking up a lot of things. If you find the Rigidbody section it pretty much tells you all the functions it uses and you can have it show you how in C# or java.

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 martin_cork · Aug 11, 2011 at 10:50 PM 0
Share

Hi DoubleDouble, thanks for helping me out on this. Righto, at least now I know that I was looking to use the wrong function!

I'll try that out tomorrow (gotta sleep) but I took a quick look and it looks promising enough, so hopefully I'll be able do what I want to do with it :)

Yeah, I've been reading the script reference quite a lot since I've ran into this problem in the last week, but I just cant seem to figure it out :S Thanks again :)

avatar image DoubleDouble · Aug 11, 2011 at 11:13 PM 2
Share

No problem, next time click "add new comment" below my answer ins$$anonymous$$d of adding a new answer. If my answer helps you figure it out tomorrow make sure to accept it.

avatar image martin_cork · Aug 12, 2011 at 08:33 PM 0
Share

Hi, so SmoothDamp works alright, but turns out it doesnt entirely solve my issue but does go half the way.

I need to be able to set the target position of my rigidbody dynamically (not sure if dynamically is the word, more used of html coding :o ) ie. if the rigidbody can be moved in lots of different directions it should come to rest (the target position) in lots of different places but so far I can only set one place, the Transform target in the Unity GUI. Any ideas on how to solve this issue?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Moving a player with Rigidbody 2 Answers

Why doesn't my rigidbody velocity limiter script work properly? 1 Answer

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

How to make gameobjects fall down faster with each update ? 1 Answer

GameObject disappears when velocity is set to (near) zero. 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