Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by straydogstrut · May 19, 2010 at 03:23 AM · movementrigidbodyspeed

Pushing rigidbodies around

Related to my movement question (which 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 while he's touching/pushing the object.

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

// this script pushes all rigidbodies that the character touches var pushPower = 2.0;

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

 // We dont want to push objects below us
 if (hit.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 (hit.moveDirection.x, 0, hit.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 think of this.

The CharacterController's Move function returns a CollisionFlags object. This detects whether an object is in contact with the top, sides or base of the controller. If you check this in the Update/FixedUpdate function, you can tell if the object has stopped touching 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

Hmm, I'm thinking pasting this answer - and the one about NPC's rotating around a waypoint - over here may be doing more for my rep points than Andeeee's? Feel free to replace these answers yourself Andeeee. Thanks again.

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

No one has followed this question yet.

Related Questions

Rigidbody speed in some senes different?! 1 Answer

Rigidbody regenerated acceleration movement ? 0 Answers

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

How to make an object without Rigidbody move at the same speed as an object with Rigidbody? 1 Answer

When I use rigidbody.Moveposition, the object doesn't move accurately. 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