Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Ai random movement help!

Author
Message
Graysire
11
Years of Service
User Offline
Joined: 18th Oct 2013
Location:
Posted: 6th Mar 2014 19:05
I'm trying to make an AI move in random directions in my game I tried something like this

When I do this code though the AI is very jittery please help!
timer help
11
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 6th Mar 2014 19:14 Edited at: 6th Mar 2014 19:18
So your AIP is wrong, your supposed to do:
AIP#=rnd(1)

Also, if you want it to move in random directions you need this code:

AIP#=rnd(1)
rnd object 1

If this doesn't work, I will need your whole code to further help you.
Graysire
11
Years of Service
User Offline
Joined: 18th Oct 2013
Location:
Posted: 6th Mar 2014 19:24
um ok rnd object 1 isn't even a command this was extremely unhelpful.....
Graysire
11
Years of Service
User Offline
Joined: 18th Oct 2013
Location:
Posted: 6th Mar 2014 19:25
Oh and this command is in a do loop!
timer help
11
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 6th Mar 2014 19:26
If you put your mind to it, anything is possible
Graysire
11
Years of Service
User Offline
Joined: 18th Oct 2013
Location:
Posted: 6th Mar 2014 19:30
That doesn't really help
timer help
11
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 6th Mar 2014 19:31
See, your not believing, your supposed to believe in yourself and it can work, you don't need people to give you the answers. Just believe
CSL
16
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: USA
Posted: 6th Mar 2014 20:04 Edited at: 6th Mar 2014 20:06
Try rnd(1)+1 instead of rnd(2).

rnd(2) will result in 0,1, or 2, which could affect your logic if there's no condition to capture the result of 0.

rnd(1) includes 0 and 1, and rnd(1) + 1 will limit the results to 1 or 2

Also, try using an integer variable, AIP instead of AIP#.

CSL
chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 6th Mar 2014 20:53
Quote: "When I do this code though the AI is very jittery please help!"


Hi there. You are using a very small random number. Try this:



I'm not a grumpy grandpa
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 6th Mar 2014 21:13
What I'd do for simple random direction code, is store the current timestamp and x/z position for the AI, then every X milliseconds or when the distance between the stored position gets too great, choose another direction, then reset the timestamp and position and repeat.

This way, your AI will move in a constant direction then change direction randomly. I use this for my random zombie code in the codebase: here

ShellfishGames
12
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 6th Mar 2014 22:25
I believe chafari's solution is very suitable here. Instead of moving your AI agend randomly each frame, store its current direction in a variable and change this direction randomly, but rarely.

The approach desribed by Mobiius is certainly better in the way that it gives you more control over how often exactly the movement changes and it's independent from the frame rate, but I assume in the current situation working with timers would just cause more problems or confusion.


Also..

Quote: "See, your not believing, your supposed to believe in yourself and it can work, you don't need people to give you the answers. Just believe "


Well. While there is certainly truth to this, it did kind of remind me of something.

Graysire
11
Years of Service
User Offline
Joined: 18th Oct 2013
Location:
Posted: 7th Mar 2014 19:05
All I want the object to do is randomly strafe it should not be too complicated!
ShellfishGames
12
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 7th Mar 2014 19:14 Edited at: 7th Mar 2014 19:16
Chafari's example is pretty short and not that complicated...

This is the simplest way of implementing it I can think of:



You need:
-your object
-a variable
And that's it.

The variable defines in what direction your object is moving. So make the movement code depend on that variable. And change the variable in random intervals.

Graysire
11
Years of Service
User Offline
Joined: 18th Oct 2013
Location:
Posted: 7th Mar 2014 19:38
THANK YOU VERY MUCH shellfish this seemed to work!
wattywatts
15
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 7th Mar 2014 22:09
After the fact, I'm curious why you want your AI to move in random directions instead of random waypoints? Must be an arcade style game I guess?

New sig coming soon..
tiffer
19
Years of Service
User Offline
Joined: 6th Apr 2006
Location: Scotland
Posted: 16th Mar 2014 23:06
Quote: "Well. While there is certainly truth to this, it did kind of remind me of something. "


Ah that's where feed me got his soundbyte from.

Cwatson

Login to post a reply

Server time is: 2025-05-14 03:14:20
Your offset time is: 2025-05-14 03:14:20