AI Moving Problem
AI Moving Problem
AI Moving Problem
AI Moving Problem
AI Moving Problem
AI Moving Problem AI Moving Problem AI Moving Problem AI Moving Problem AI Moving Problem AI Moving Problem AI Moving Problem AI Moving Problem
AI Moving Problem AI Moving Problem
AI Moving Problem
Go Back  Xtreme Visual Basic Talk > > > AI Moving Problem


Reply
 
Thread Tools Display Modes
  #1  
Old 05-30-2011, 11:08 AM
VbNerd96's Avatar
VbNerd96 VbNerd96 is offline
Freshman
 
Join Date: Dec 2009
Posts: 33
Question AI Moving Problem


Ok, so. I've been working on a game, nothing big just a small project a friend wanted me to make lol, and I've encountered a bit of a problem.

The game's AI is rather simple, but I've added a function so that It'll move to a specific spot when told to do so.

Code:
    Select Case State
        
        Case "idle"
            RunState = 0
        
        Case "moving to spot"
            If movePX > X Then
                X = X + 2
            ElseIf movePX < X Then
                X = X - 2
            ElseIf movePX = X Or movePX = X + 1 Or movePX = X - 1 Or movePX = X + 2 Or movePX = X - 2 Then
                X = movePX
            End If
            
            If movePY > Y Then
                Y = Y + 2
            ElseIf movePY < Y Then
                Y = Y - 2
            ElseIf movePY = Y Or movePY = Y + 1 Or movePY = Y + 2 Or movePY = Y - 2 Or movePY = Y - 1 Then
                Y = movePY
            End If
            
            If X = movePX And Y = movePY Then
                State = "idle"
            End If
            
            Walk
            
    End Select
The problem with this is that the AI will approach it's destination and then "vibrate" back and forth over it... never actually reaching where it was supposed to go.

If anyone knows what I'm doing wrong, or if there's a better way, I would greatly appreciate it. Thanks in advance.
__________________
Je reste fidèle à la cause... Des langue programmation de VB6!
Reply With Quote
  #2  
Old 05-30-2011, 12:33 PM
Rockoon's Avatar
Rockoon Rockoon is offline
Joseph Koss

* Guru *
 
Join Date: Aug 2003
Location: Unfashionable End
Posts: 3,615
Default

You probably meant to have the final ElseIf cases (movePX = X Or movePX = X + 1 Or movePX = X - 1 Or movePX = X + 2 Or movePX = X - 2) come before the first two tests that you are doing.

Otherwise much of this expression is irrelevant for X must be equal to movePX (neither greater than, nor less than) and Y must be equal movePY when you get to those tests.
Reply With Quote
  #3  
Old 06-03-2011, 05:27 PM
VbNerd96's Avatar
VbNerd96 VbNerd96 is offline
Freshman
 
Join Date: Dec 2009
Posts: 33
Default

Oh my god. -.- I feel really stupid now. XDD
Thank you so much though.
__________________
Je reste fidèle à la cause... Des langue programmation de VB6!
Reply With Quote
Reply

Tags
artificial, help me, intelligence, vb6


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
AI Moving Problem
AI Moving Problem
AI Moving Problem AI Moving Problem
AI Moving Problem
AI Moving Problem
AI Moving Problem AI Moving Problem AI Moving Problem AI Moving Problem AI Moving Problem AI Moving Problem AI Moving Problem
AI Moving Problem
AI Moving Problem
 
AI Moving Problem
AI Moving Problem
 
-->