|
Ok I have an AI script that works (so far), except for the obstacle avoidance. What I want is, when one of the raycast hits an object for it to turn and then continue to head towards the target (which may turn from the next waypoint to the player). The problem is that the enemy jitters in a certain direction and then tries to go to the waypoint. Also is there anyway I can write this in less code? I'm pretty noob at complex stuff like this, the collision detection was horribly written but sort of works aside from the jittering instead of turning and then trying to go to the waypoint. Here is the code, it's very long:
(comments are locked)
|
|
I'm doing something similar and ran into the same problem. To stop the jittering, you need to stop the your game object from trying to head to your next waypoint, until it's passed the obstacle. I did this by creating a temporary waypoint at the colission point, and then moving the temporary waypoint along the z axis until the raycast hits stopped. You need to store the original waypoint you're heading too, and then re-establish it once you reach the temporary waypoint, and then destroy the temporary waypoint. You could also add some velocity retardation based on distance if you needed too. Hope this helps (took me a few nights to work this out) Chris
(comments are locked)
|
|
I think I had a similar problem with my NPC. For collision avoidance, I looked at the tangent points of the obstacle to define the new target and what happened is that for 1 frame direction was corrected by the collision avoidance, but the frame after, the path was clear and the direction was setup by the next waypoint, however while moving the NPC, the next frame made it necessary to correct again. So it alternated between a waypoint target and a fixed target, making the character to jitter. What I did was simply smoothing the current rotation to the expected rotation, hence reducing the jitter, with something like: rigidbody.MoveRotation(Quaternion.Slerp(rigidbody.rotation, Quaternion.LookRotation(look), 0.2f)); It's not perfect though, but it's a first step in the right direction I think. Thanks I'm gonna try it.
May 27 '12 at 08:40 PM
Chimera3D
(comments are locked)
|
|
One name....SimplePath. Really? Youre going to give me negative karma for suggesting something that will make your life so much easier than writing 1000 lines of uncertain object avoidance code?....
May 27 '12 at 04:08 AM
GC1983
I don't see misinformation or something that is wrong in this answer. Well it's not that comprehensive, but nothing that would explain a downvote. If you downvote a post, give at least a reason in a comment. Voting is nothing personal here. This is like a wiki to collect knowledge for the whole community. I'll add at least a link to increase the value of this answer ;)
May 27 '12 at 10:38 AM
Bunny83
(comments are locked)
|
