{"author_link":"\/users\/jamfella","author_name":"jamfella","author_uid":"jamfella","comments":[],"epoch":1525358364,"event":"LD41","format":"md","ldjam_node_id":95918,"likes":4,"metadata":{"p_key":"114737","p_author":"jamfella","p_authorkey":"1088789","p_urlkey":"330697","p_title":"How I built cop AI and \"look for evidence\" system using Unity","p_cat":"LDJam ","p_event":"LD41","p_time":"1525358364","p_likes":"4","p_comments":"0","p_status":"WAYBACK","us_key":"1088789","us_name":"jamfella","us_username":"jamfella","event_start":"1524182400","event_key":"72","event_name":"LD 41"},"node":{"_collation":{"body_sanitizer":"TextUtils::SanitizeHTML via existing importer","event":"LD41","removed_author":false},"_superparent":73256,"_trust":1,"author":88789,"body":"Barry Has a Secret is a game where Barry has something to hide. One part of the game is that cops will be appearing looking for something. They wander in the apartment. Some people asked me how I built this thing, so here's a short post about \"looking for evidence\" system.\n\nIn a nutshell: This is simple navigational mesh in Unity. Cops moves to randomized location every 5-8 seconds and uses raycasting for looking for target.\n\n![barry_gaze_system_01_small.gif](\/\/\/raw\/5da\/51\/z\/149c4.gif)\n\nCore part of the gameplay is that cops are looking for evidence. \n\nHow this works is basically:\n\n1) Cop moves around for 5-8 seconds and stops\n\n2) Cop has \"eyes\" transform near his, well, character model head. This has the nice effect that cop literally cannot see \"through his head\". If there's anything between \"eyes\" and \"evidence\", the cop won't notice it.\n\n3) Once cop has stopped, The \"eyes\" transform sends \"raycast\" towards each of the evidence (like axe). So if there's 10 pieces of evidence, then cop will send 10 \"rays\" per stop.\n\n4) Game counts how many items cop spotted. If he spots more than 1, you are busted. \n\n5) Character idle animation is such, that the head rotates (and this could affect the gaze a bit)\n\n![barry_gaze_system_03_small.gif](\/\/\/raw\/5da\/51\/z\/149c5.gif)\n\nA simple navigation mesh in level geometry, bit of randomization for cop movement, and then raycasting.\n\nThis stuff combined together, creates pretty convincing and thrilling cop experience. \n\nMandatory self-plug: \"Barry Has a Secret\" (both jam & post-jam) versions are available here: http:\/\/ldjam.com\/events\/ludum-dare\/41\/barry-has-a-secret-horror-blood-meal-hiding-simulation\/\n\nThanks for reading.","comments":2,"comments-timestamp":"2018-05-03T16:46:15Z","created":"2018-05-03T14:19:49Z","files":[],"files-timestamp":0,"id":95918,"love":4,"love-timestamp":"2018-05-03T17:00:24Z","meta":[],"modified":"2018-05-03T17:00:24Z","name":"How I built cop AI and \"look for evidence\" system using Unity","node-timestamp":"2018-05-03T14:39:24Z","parent":88794,"parents":[1,5,9,73256,88794],"path":"\/events\/ludum-dare\/41\/barry-has-a-secret-horror-blood-meal-hiding-simulation\/how-i-built-cop-ai-and-look-for-evidence-system-using-unity","published":"2018-05-03T14:39:24Z","scope":"public","slug":"how-i-built-cop-ai-and-look-for-evidence-system-using-unity","subsubtype":"","subtype":"","type":"post","version":283630},"node_metadata":{"n_key":"95918","n_urlkey":"330697","n_parent":"88794","n_path":"\/events\/ludum-dare\/41\/barry-has-a-secret-horror-blood-meal-hiding-simulation\/how-i-built-cop-ai-and-look-for-evidence-system-usi","n_slug":"how-i-built-cop-ai-and-look-for-","n_type":"post","n_subtype":"","n_subsubtype":"","n_author":"88789","n_created":"1525357189","n_modified":"1525366824","n_version":"283630","n_status":"WAYBACK"},"source_url":"https:\/\/ldjam.com\/events\/ludum-dare\/41\/barry-has-a-secret-horror-blood-meal-hiding-simulation\/how-i-built-cop-ai-and-look-for-evidence-system-using-unity","text":"Barry Has a Secret is a game where Barry has something to hide. One part of the game is that cops will be appearing looking for something. They wander in the apartment. Some people asked me how I built this thing, so here's a short post about \"looking for evidence\" system.\n\nIn a nutshell: This is simple navigational mesh in Unity. Cops moves to randomized location every 5-8 seconds and uses raycasting for looking for target.\n\n![barry_gaze_system_01_small.gif](\/\/\/raw\/5da\/51\/z\/149c4.gif)\n\nCore part of the gameplay is that cops are looking for evidence. \n\nHow this works is basically:\n\n1) Cop moves around for 5-8 seconds and stops\n\n2) Cop has \"eyes\" transform near his, well, character model head. This has the nice effect that cop literally cannot see \"through his head\". If there's anything between \"eyes\" and \"evidence\", the cop won't notice it.\n\n3) Once cop has stopped, The \"eyes\" transform sends \"raycast\" towards each of the evidence (like axe). So if there's 10 pieces of evidence, then cop will send 10 \"rays\" per stop.\n\n4) Game counts how many items cop spotted. If he spots more than 1, you are busted. \n\n5) Character idle animation is such, that the head rotates (and this could affect the gaze a bit)\n\n![barry_gaze_system_03_small.gif](\/\/\/raw\/5da\/51\/z\/149c5.gif)\n\nA simple navigation mesh in level geometry, bit of randomization for cop movement, and then raycasting.\n\nThis stuff combined together, creates pretty convincing and thrilling cop experience. \n\nMandatory self-plug: \"Barry Has a Secret\" (both jam & post-jam) versions are available here: http:\/\/ldjam.com\/events\/ludum-dare\/41\/barry-has-a-secret-horror-blood-meal-hiding-simulation\/\n\nThanks for reading.","title":"How I built cop AI and \"look for evidence\" system using Unity","wayback_source":[]}