0 Replies - 1016 Views - Last Post: 03 May 2017 - 01:52 PM

#1 AnonymousUser1508  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 29-April 16

Wander steering Behaviour jitters

Posted 03 May 2017 - 01:52 PM

Hi Everyone,

I am trying to implement the Wander steering behaviour using the seek behaviour to make the entity move to the target location. Once it gets to the target location it seems to 'shake' at that location as if it wants to move but is stuck at that location. Checking the console log reveals that it moves around 60 pixels. I decided to add an if statement (Commented out code) to make it move every 4 seconds but then it stayed at that location and didn't move at all from there. At the minute I am not quite sure how to proceed in order to get the enemy entity to Wander randomly. Is the way I am doing things along the right lines or am I way off?

Any help is greatly appreciated.

Thank you.

Wander Class

        private Vector2 WanderDirection;
        private float wanderRadius = 200f;
        private float wanderJitter = 20.4f;
        private float offset = 5;
        int now = 4000;
        float elapsed;
        
        SeekBehaviour seek = new SeekBehaviour();
        Random random = new Random();
             
        
        public void wanderBehaviour<T>(T Entity, GameTime gt) where T : ISprite
        {
            elapsed += (float)gt.ElapsedGameTime.TotalMilliseconds;

            // (elapsed > now)
           // {
                Vector2 targetPosition = WanderDirection - Entity.Pos * offset;
                targetPosition = new Vector2(targetPosition.X + (random.Next((int)-wanderJitter, (int)wanderJitter)),
                    targetPosition.Y + random.Next((int)-wanderJitter, (int)wanderJitter));
                Console.WriteLine(targetPosition);
                targetPosition.Normalize();
                targetPosition = targetPosition * wanderRadius;
                WanderDirection = WanderDirection * offset;

                targetPosition += WanderDirection * (float)gt.ElapsedGameTime.TotalMilliseconds;
                seek.seek(Entity, targetPosition, gt);
                //elapsed = 0;
            //}
        }


Level 1 class

public override void LoadContent()
        {
            b = new Player(new Vector2(300, 200), GlobalProperties.Instance.Content.Load<Texture2D>("back"));
            a = new Enemy(new Vector2(200, 200), GlobalProperties.Instance.Content.Load<Texture2D>("back"));
            s.Add(a);
            s.Add(B)/>/>;

            base.LoadContent();
        }


Update method in level 1

 wander.wanderBehaviour(a, gameTime);


Is This A Good Question/Topic? 0
  • +

Page 1 of 1