• 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
2
Question by straydogstrut · May 19, 2010 at 03:23 AM · movementrigidbodyspeed

Pushing rigidbodies around

Related to my movement question (w$$anonymous$$ch looks to be resolved by Mike, thanks), but it's different enough to warrant its own question.

I'm using the OnControllerColliderHit script from the docs to push rigidbodies around with no problems. What i'd now like to do is keep the initial jolt that I give an object (since the player will be running at speed), but thereafter slow my character's movement speed down w$$anonymous$$le he's touc$$anonymous$$ng/pus$$anonymous$$ng the object.

I can change the speed in OnControllerColliderHit, but I don't have a way to reset it after the character stops touc$$anonymous$$ng the object. I tried using triggers, but then the character slows down just before he makes contact. T$$anonymous$$ngs got a bit messy when I tried using various booleans and/or distance checks. Below is the unmodified pus$$anonymous$$ng script.

// t$$anonymous$$s script pushes all rigidbodies that the character touches var pushPower = 2.0;

function OnControllerColliderHit ($$anonymous$$t : ControllerColliderHit) { var body : Rigidbody = $$anonymous$$t.collider.attachedRigidbody; // no rigidbody if (body == null || body.isKinematic) return;

 // We dont want to push objects below us
 if ($$anonymous$$t.moveDirection.y < -0.3) 
     return;

 // Calculate push direction from move direction, 
 // we only push objects to the sides never up and down
 var pushDir = Vector3 ($$anonymous$$t.moveDirection.x, 0, $$anonymous$$t.moveDirection.z);

 // If you know how fast your character is trying to move,
 // then you can also multiply the push velocity by that.

 // Apply the push

// body.velocity = pushDir pushPower; body.velocity = pushDir moveChar.currentSpeed;

}

Anyone have any ideas? Thanks

Comment
Add comment
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

1 Reply

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

Answer by straydogstrut · May 22, 2010 at 01:38 PM

Response from Andeeee on the Unity forum. I'm ashamed I didn't t$$anonymous$$nk of t$$anonymous$$s.

The CharacterController's Move function returns a CollisionFlags object. T$$anonymous$$s detects whether an object is in contact with the top, sides or base of the controller. If you check t$$anonymous$$s in the Update/FixedUpdate function, you can tell if the object has stopped touc$$anonymous$$ng another rigidbody and then restore its speed to normal.

Comment
Add comment · Show 1 · 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 straydogstrut · May 22, 2010 at 01:44 PM 0
Share

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Change movement speed based on rotation 0 Answers

Rigidbody speed in some senes different?! 1 Answer

How to add max speed to 3D rigidbody? 1 Answer

How to limit the force from player input without limiting speed 2 Answers

Rigidbody regenerated acceleration movement ? 0 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