As part of the scripting in this project, I was responsible for getting our enemy wolf to perform different behaviours and react to stimulus within its environment.
Raycasting.
Following prior research (found in a previous post) I decided to use Raycasting as the "sight" for the wolf. This raycast would constantly be projected from the front of the character model and make the character react accordingly depending on what it hit (or not).
State based behaviour.
This refers to the three basic functions that the enemy will perform depending on what it "see's";
Natural State - Where in the wolf will patrol predefined way points, just going about its business.
Baited State - Triggered by raycast if it hits a game object tagged as "bait". The wolf will then deviate from its patrol route and investigate the game object before returning to the natural state.
Hostile State - This is where the wolf has detected our player and will proceed to move toward and kill them via interacting with the Health variable set on the player.
Initially the above states were their own separate Boolean Variables which would need to be set from true to false at regular intervals through out the script.
However, under advisement of a more experienced programmer this was later changed to a String variable, significantly reducing the lines of code required.
Rigidbody vs Character Controller -When first setting up the patrol system in the "Natural State" the wolf had a Rigidbody attached to it, the idea being to propel the character along and move it that way.
However this caused several problems when implemented. First and foremost being that because the rigidbody is constantly effected by gravity, the wolf would drag along the surface of the world and severely reduced the speed of the wolf.
As well as this the physics had the potential to cause the model to fly up into the hair at random intervals.
Upon further research (and a lot of rewriting of script) the wolf now has a Character Controller to direct its movement.
Lesson learned - Rigidbody for bullets.
(DS 11/03/12)
No comments:
Post a Comment