- Home /
Pushing the Character
I've seen many, many, many threads about how to get the Character to push a rigidbody etc etc. I havn't seen any threads that explain how to get that same rigid body to just push the character.
What I'm attempting to do in the code I'm working on is to make it so that a Block will push the character. Basically the Block snaps to a block below it. But if the player is in the way the Block that is supposed to snap will just get nudged over instead of the player. I want the player to be pushed away by the Block, not the other way around.
Any helpful advice, suggestions, or questions about what it is I'm trying to do are warmly welcomed. I got nothing. I've tried a few different things but no luck and im just stuck again.
Answer by Chris D · Jul 04, 2011 at 04:50 PM
I believe, and I could be wrong on this, the problem is that the Character controller is Kinematic and thus won't respond to outside forces unless you tell it to through scripting.
Your blocks will deflect off of it because it has a collider but, for all intents and purposes to the block's collider, it's seen as an immoveable object.
I think you'll have to add in some collision code for your controller to say
OnCollisionEnter(col: Collision){
//push me with the appropriate force
}
edit
Upon another search through the answers, it looks like you have to have a rigidbody attached for physics (don't know why I didn't realize that the first time...)
So basicly I have to rewrite my code so the player is controlled via a Rigidbody rather than a CharacterController.
Since the CharacterController and Rigidbody components conflict with eachother, I cant simply add a Rigidbody to the Character whilst having a CharacterController on it as well.
At least, that is how I understand it. Idk if its because of my limited knowledge in program$$anonymous$$g or not, but I tried a few different things that should have caused the character to do something. However, the Character didn't budge at all.
Continued advice would be welcome, although I'm tempted to start reworking the code I have.
I actually haven't used the controller much so maybe someone else can speak to whether or not a total re-write is needed. Have you tried calling simple move in conjunction with OnCollisionEnter? It does seem to me that letting unity handle the physics would be a better option here...
Alright, well I may be back to again to ask various questions about manipulating rigidbodies.
Thank you for the assistance. I may post any solutions I come across using the Character Controller method here.
Your answer
Follow this Question
Related Questions
Character Controller Jittering 0 Answers
character joint scripting HELP!!! 1 Answer
how to make character controller push rididbodies 1 Answer
Flying collision 0 Answers
How to set Player to push only during pushing animation 1 Answer