Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MajorParts · Jun 03, 2015 at 11:32 AM · c#ainavmeshpacman

delaying the start of a navmesh agent

Hi. I am making a 1st person version of pacman and I'm having trouble with the ghost ai. I've based the way they navigate the maze on the original namco arcade game.

The problem I'm having is when the ghosts start to move and what "mode" they are in. I have variables set up so that each of the 4 ghosts start when a certain amount of dots have been eaten. 2 of them are set to 0, 1 is set to 30 and the 4th is set to 60. This works as intended, but the "mode" also doesn't start until the ghost does. I only have 2 of the 3 ghost modes so far, "chase" and "scatter". "Frightened" will come later and will no doubt be a whole new problem!

For simplicity, the modes always last the same amount of time...7 seconds of "scatter" followed by 20 seconds of "chase" and repeat. The 2 ghosts that start on 0 dots, start in "scatter" mode. If I eat 30 dots when they are in "chase" mode, the 3rd ghost will become active and be in "scatter" mode when he should be in the same mode as the others.

So, how would I go about delaying the start of a ghost but keep his mode in line with already active ghosts?

I shall keep plugging away trying things but chopping things out of 1 script and putting in another is confusing me and just breaks everything :D

my ghost code.... ignore "ghostMode", that is for when I do the "frightened" mode

 using UnityEngine;
 using System.Collections;
 
 public class GhostAI : MonoBehaviour 
 {
     public static int ghostDots;
     public int startDots;
     public Transform chase;
     public Transform scatter;
     private int ghostMode = 1;
 
     public int chaseSeconds = 20;
     public int scatterSeconds = 7;
     private float currentSeconds = 0f;
     
     private NavMeshAgent agent;
     
     void Start () 
     {
         agent = gameObject.GetComponent<NavMeshAgent>();
 
     }
     void Update()
     {
         ghostDots = EatingScript.dotCount;
         
         currentSeconds += Time.deltaTime;
 
         if (ghostDots > startDots) {
 
             if (currentSeconds < scatterSeconds && ghostMode == 1) {
                 agent.SetDestination (scatter.position);
                 //Debug.Log("Scatter Mode");
             }
 
             if (currentSeconds > scatterSeconds && ghostMode == 1) {
                 agent.SetDestination (chase.position);
                 //Debug.Log("Chase Mode");
             }
 
             if (currentSeconds > chaseSeconds && ghostMode == 1) {
                 currentSeconds = 0;
             }
         }
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MitchWardle180 · Jun 04, 2015 at 07:26 AM

It may be happening because all of the monsters have there own script, maybe create a "MonsterManager" script which handles the amount of monsters in an array or list and also which mode they are in. This would allow you to have functions to retrieve information about the monster or mosters whilst keeping them in the same state

Hope this helped

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MajorParts · Jun 05, 2015 at 02:40 AM 0
Share

Thanks, you could be right, but everything else worked at the time of asking and as a beginner, I'm confused by the use of arrays, and so didn't want to drastically change everything. I may have to I suppose, as I implemented "Frightened" mode recently and couldn't get that to work properly. They went into frightened mode, but it all messed up when I tried to eat one :D Frightened mode was handled by the players "eating" script. I moved it to the ghosts AI script and I'm now getting extremely frustrated, as frightened mode only ever gets applied to one of the ghosts. At one point I managed to get all 4 into frightened, but unable to get more than one to go back to not frightened. I'm about to post another question :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Need help detecting barriers for my game 0 Answers

Make a flying enemy ? 0 Answers

Navmesh agent forward movement 1 Answer

is it possible to use navmesh on flying character and target ? 0 Answers

I cannot get a SetDestination to function within a set array. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges