- Home /
Custom Controller
Hello everyone, I'm trying to avoid using the Character Controller since its now what i'm looking for in my project, also I don't want to use rigid body on my Character. So I was trying to create a player that if it collides with the ground make the player stop falling or going through floor. if not hitting floor then keep falling.
here is part of my code
public bool Grounded;
void FixedUpdate()
{
if(!Grounded)
{
transform.Translate(new Vector3(0,(float)-9.8/50,0));
}
}
void OnCollisionEnter(Collision Col)
{
if (Col.gameObject.name == "Ground")
{
Grounded = true;
}
}
void OnCollisionExit(Collision Col)
{
Grounded = false;
}
When I take the Rigidbody off the OnCollisionEnter has no effect at all. When I put it back on it works fine but don't want to use Rigidbody.
the only reason i can think of for not using a rigidbody is if you want to have a character controller on your object. other than that you should just put a rigidbody on it.
if you check all the constraints, and turn gravity off, the rigidbody shouldn't effect your game, besides allowing codes like the one above to work
and if you want have a character controller, well....
i don't know how those work. so just consider this comment a bump to get your real answer if you want a character controller
Have you tried using a rigidbody with Is $$anonymous$$inematic checked? This tells the physics engine it's a moving body but almost all the movement comes from outside the physics engine. See the table at the bottom of this page about why static collider vs. static collider doesn't receive collision events: http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html
If it moves it should have a rigidbody, basically. Especially if you want to use collision/trigger events you must have a rigidbody. Not wanting one just makes no sense.
Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached.
But the character controller doesn't require the rigid body, I'm trying to make my own character controller. So I can learn how to create a custom controller without the need of a rigid body but what you guys are saying is that you have to have on the character anyways but just make it kinetic.
its non-kinematic, not kinetic : http://docs.unity3d.com/Documentation/Components/class-Rigidbody.html
You cannot make such statement without fully understanding the workings of the Character Controller Component. This has some Unity wizardry working behind the scenes. It does in fact have some sort of rigidbody that makes it work. There are other examples that prove it to be an exceptional case. A Character Controller Component :
is always a capsule collider
cannot be rotated
has its own collision events ( OnControllerColliderHit )
Answer by Kavorka · Apr 19, 2014 at 08:42 AM
If you don't want a rigidbody on your character, and you want the character to follow uneven terrain, you have to use raycasting. Search for raycasting and grounded. Since you are doing a custom controller you may be inspired by a custom controller I made, without any rigidbodies. Video link to moving platforms character controller.
That was great video and you did that all with raycasting? So you have a player with raycasting in the direction of how the player would fall and if raycasting detects a floor below the player then grounded would be true.
All raycasting. Raycast down, if ground is close enough: grounded = true. There are some maths going on. Since you are not falling by the physics engine, you have to do the math and physics yourself. It is perfectly doable (as evident from the video). Some of it may be a little tough without an engineering degree though.
Your answer
Follow this Question
Related Questions
How to get movable/pushable cubes right? 0 Answers
how to Apply Gravity at Run time ..????????? 2 Answers
How to make player collide with ground? 1 Answer
How to hit gameobjects to go into the opposite direction of hit? 1 Answer
Collision If Statement And Falling throught the ground (2 questions) 1 Answer