- Home /
Collisions without physics
Hi!
I'm trying to make the simplest platformer prototype with the simplest physics (falling with gravity, moving left and right, and (maybe) jump). For example:
void Move () {
if (!isDying || !isDead || !isShooting || !isFalling)
{
float amountToMove = Time.deltaTime * Input.GetAxis("Horizontal") * playerSpeed;
transform.Translate(Vector3.right * amountToMove);
}
}
void ApplyGravity() {
float amountToMove = Time.deltaTime * gravity;
transform.Translate(Vector3.down * amountToMove);
}
The problem is i don't know how to make collisions without physics and with isKinematic enabled. The only thing i know is to use a OnTriggerEnter function, so added a isTrigger to all objects and wrote (Hero.cs):
void OnTriggerEnter (Collider otherGameObjectCollider) {
if (otherGameObjectCollider.gameObject.tag == "ground") {
Debug.Log("ground/wall collision");
}
}
I know that i need stop my hero to prevent falling (walking) through the ground but i really can't think it out.
Sorry for the dumb question.
Answer by Dan Miller · Feb 20, 2013 at 07:33 PM
in the OnTriggerEnter function you could set your gravity variable equal to 0. That way the amountToMove would equal 0 and your player wouldn't be moving the downward direction.
Your answer
Follow this Question
Related Questions
OnTriggerEnter function giving mixed results 1 Answer
Multiple collisions not working.Plz help 0 Answers
Shooting myself 0 Answers
Destroying object on collision 3 Answers
On Trigger Enter, Collide with object, specific collision 1 Answer