Trio Game -Line of Sight Update

To start this lesson off we were shown some examples of how to calculate dot products of some vectors, using a different method to the one I had researched last week:

dot-product-2

 

 a · b = ax × bx + ay × by

 

dotproductpractice

Above were the examples (with answers now included) we were asked to work through during the lecture. After all the confusion I had researching these the week before, it all boils down to some multiplication between vectors. I don’t normally post any workings we do mid lecture but this time around I thought it would help me leaving them here for reference.

So if the end number is positive, it means there are less than 90º between two objects and if its negative there are more than 90º between the two.

So all of this is the background theory behind what we would implement in our games today. Guard line of sight/cone of vision. The code was supplied by Ant, as per usual and we jumped right in and pasted this into the existing guard script. It worked but the cone only ever pointed in one direction, and we felt it should change depending on the direction the guard was heading.

Ant assisted us in correcting this by using the direction of the guard waypoints to determine the facing direction.

waypointmovetowardschecktargetincone

 

Further adding features we wanted the guard to be able to shoot towards the player when they are within their cone of vision. Sounds easy enough but again, after much googling and frustration we ended up asking Ant who spent a great chunk of time adding this functionality. I believe we determine the direction of the projectile by taking the searchTarget position and substracting the transform.position.

newautofire

gameexample3

I must admit we’ve reached a point in programming where it really is getting beyond me, the best I can do in these blogs is summarise what happened. Explaining in detail is becoming troublesome. The college is still unsure what will make it into the programming exam and what won’t, so I’m busy crossing all fingers and toes that this level of scripting isn’t required. I won’t deny that the end results are great, I’m having fun playing our own game and it’s only had three works of lesson time put into it.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s