|
Hello, I am a Unity newbie. I have a bug model that crawls around randomly on the X/Z plane, using transform.Translate. I also have a terrain which I have set as a Mesh Collider. What I want is for the bug to crawl around on the terrain, setting his orientation to match the polygons he's crawling on. However, I'm having difficulty doing this with just the default collision functions. How can I determine the Z position of the terrain below my bug model? Can I get the orientation of this point, so I can use it as my model's "up" vector?
(comments are locked)
|
|
I found a reasonable answer to my problem. I used raycasting to find the proper Y coordinate, then used the normal to set orientation. I still wish I had a better handle on collision detection, but that's for another day I suppose...
(comments are locked)
|
|
Here, this code should do the trick:
It ensures that your bug's Y will be the same as the Y of the last thing it touched. Thanks for your help. I'm actually having trouble even getting functions like OnCollisionEnter to execute. I gave the terrain a mesh collider. Then, I gave my bug a box collider. Nothing happened. Then, I gave my bug a RidigBody component, and checked Is Kinematic. Still, nothing happened. I even tried making the terrain a RigidBody, to no avail. OnCollisionEnter just doesn't seem to be getting called. Am I missing something? :[
Jun 17 '10 at 10:03 PM
UltimateWalrus
(comments are locked)
|
|
If you're using a CharacterController you need to hook into the OnControllerColliderHit. Here's some C#:
(comments are locked)
|
