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
0
Question by · Sep 07, 2010 at 03:41 AM · rigidbodycollidercharactercontrollerplatformermoving-platform

Moving platform clips through character controller

Edit: Abridged Version

I have a 3d platformer setup with a PlayerCharacter using CharacterController.Move and moving platforms with kinematic rigidbodies being moved by rigidbody.MovePosition.

If the PlayerCharacter is stationary, the platforms move through it without colliding. However, if the PlayerCharacter is moving, the collision is correctly detected.

Is this an appropriate setup for moving platforms? Have I overlooked something obvious? Does anyone have any tips for where to start when debugging this? Further details below - I've attempted to debug/fix this a number of ways, with no success so far.


I've been working on a 3d platformer. I have a Player object with a ThirdPersonController (using CharacterController.Move()) and SpringFollowCamera (harvested/modified from the 3D Platform Tutorial), and I've written generic platform movement code. The Player character is attached to the platform when it stands atop it, and can move around as the platform moves - based on the code given by Rune's answer to a similar question.

My initial implementation of the platforms was directly setting the transform.position, and I understood that it would clip through the character. However, I have changed to rigidbody.MovePosition(), and there are still clipping issues under some circumstances.

With the transform.position implementation:

  • When the platform stops at either end, the Player cannot move through the platform. (intended)
  • When both the platform and Player are moving, the Player can move through the platform.
  • When the platform is moving but the Player is stationary, the platform will clip straight through the Player.

With the rigidbody.MovePosition implementation:

  • When the platform stops at either end, the Player cannot move through the platform. (intended)
  • When both the platform and Player are moving, the Player cannot move through the platform. (intended)
  • When the platform is moving but the Player is stationary, the platform will clip straight through the Player.

The platform is a kinematic RigidBody with no drag or gravity applied, and scale of (2.0, 0.5, 2.0). The Player is a Cylinder with a CharacterController of 2 hieght and 0.5 radius.

I'm still fairly new to Unity, but fairly experienced with programming and game development. Is there something obvious that I've missed here? Is there an error with my implementation of the Rigidbody on the platform, or my use of MovePosition (as below)? My only other thoughts are that the collisionFlags are being ignored when the player is stationary, but I'm not sure how or why that would be set.

I've stripped out the unrelated code (where MoveObject is called, etc).

var startPosition : Vector3; // The starting WorldPosition of the platform (used if the platform must reset) var endPosition : Vector3; // The ending WorldPosition of the platform var moveTime : float = 2.5; // How long it takes to move from one end to another var endMoveDelay : float = 0.5; // Time waited at each end without moving again

private var desiredPosition : Vector3;

function FixedUpdate() { if ( transform.position != desiredPosition ) { transform.rigidbody.MovePosition(desiredPosition); } }

function MoveObject(startPos : Vector3, endPos : Vector3, moveTime : float) { var i = 0.0; var rate = 1.0/moveTime; while (i < 1.0) { i += Time.deltaTime * rate; // transform.position = Vector3.Lerp(startPos, endPos, Mathf.SmoothStep(0.0, 1.0, i)); // was using this before rigidbody implementation desiredPosition = Vector3.Lerp(startPos, endPos, Mathf.SmoothStep(0.0, 1.0, i)); yield; } }

Any insight is much appreciated! Cheers.

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 Ehren · Oct 01, 2010 at 09:30 PM 0
Share

Does OnControllerColliderHit get called when the platform clips the player?

avatar image · Oct 02, 2010 at 02:20 AM 0
Share

Using Debug.DrawRay(hit.point, hit.normal); it looks like it hits most of the time, but still just clips straight through. If I place a Cube the same dimensions as my player (but with a rigidbody+collider ins$$anonymous$$d of CharacterController), the cube is knocked away. I assume this is the intended design of the CharacterController - that it can't be knocked around by collisions. If this is the case, would you recommend writing custom collision behaviour for the CharacterController, or writing a custom character controller for a rigidbody+collider setup?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Ehren · Oct 02, 2010 at 07:46 PM

If OnControllerCollider gets called, you could write custom logic that allows the character to get pushed by moving kinematic rigidbodies.

Another option: Just leave it and design your levels so the clipping doesn't happen (for example, leave a gap between stationary floors and the moving platforms).

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

Answer by Mushu · Aug 21, 2013 at 11:29 AM

The character controller doesn't seem to detect collisions when it's not moving. My solution was to have the platform as a rigidbody with frozen x,y,z position and rotation. A move script on the platform would move it's "transform.position" directly and another script on the platform would detect if the platform has collided with the player and if so, send the needed data to the player script so it can react accordingly.

So basically when the character is moving it will detect a moving platform collision but when it's stationary the platform will detect a collision with the character.

Hope this helps.

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

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

1 Person is following this question.

avatar image

Related Questions

Character Controller falls through moving/rotating platforms (Not A Duplicate Post) 1 Answer

attached.Rigidbody isn't working with a ChactacterController? -1 Answers

How to deal the 2d platform physics? 0 Answers

Picking up items with Rigidbodies 2 Answers

How to make jump something without using a character contoller? 2 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