Saturday, 15 May 2010

unity3d - Collisions without physics -



unity3d - Collisions without physics -

i'm trying create simplest platformer prototype simplest physics (falling gravity, moving left , right, , (maybe) jump). 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 don't know how create collisions without physics , iskinematic enabled. thing know utilize ontriggerenter function, added istrigger objects , wrote (hero.cs):

void ontriggerenter (collider othergameobjectcollider) { if (othergameobjectcollider.gameobject.tag == "ground") { debug.log("ground/wall collision"); } }

i know need stop hero prevent falling (walking) through ground can't think out.

sorry dumb question.

you can utilize isfalling flag of hero determine whether in falling. seek this:

void applygravity() { if (isfalling) { float amounttomove = time.deltatime * gravity; transform.translate(vector3.down * amounttomove); } } void ontriggerenter (collider othergameobjectcollider) { if (othergameobjectcollider.gameobject.tag == "ground") { debug.log("ground/wall collision"); isfalling = false; } }

and when hero leave platform , not in jumping, should set isfalling true create begin fall.

maybe you'd seek see unity officail demo: 3d platformer tutorial. believe contains trick , method need build platform game. luck. : )

unity3d

No comments:

Post a Comment