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 Discussion / Simple AI help

Author
Message
sdavis117
16
Years of Service
User Offline
Joined: 15th Apr 2009
Location:
Posted: 16th Apr 2009 00:58
I currently have objects that I want to go towards the player at a set speed, but I have no idea how to code such a feat.

Can anyone help me?

Student.
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 16th Apr 2009 01:31
Here is how I would approach it(its all math)


Where object is the object number of the thing you want to follow the player and hero is the object number of the player.

Basically it finds the unit vector (don't worry if you don't know it, it is vector calculus stuff, but you can use it simply) between the object and the hero, then moves the object its movement speed multiplied by the unit vector.

What is the unit vector:
First off, a vector is a line with a magnitude (length) and direction (angle). It has components in all 2 or 3 axis. If you use components to define a vector, you don't need the angle. So a vector can be given in Radius,Angle format or Xcomponent,Ycomponent format.

A unit vector is the name for the components of a vector that is 1 unit long in a specific direction. The math isn't really important, but it is the differences in the positions (x,y,z) divided by the total length of the vector between the two points.

I don't necessarily expect most of this to make sense, so you could just go with it if you want, or if you are curious, just ask and I will try to clarify a little more thoroughly.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 16th Apr 2009 03:28
That's cool math, BN2 ! I think there might be a typo:

I never thought of using the unit vector to move something around. That's celver.

@sdavis117
Is this 3d?
Perhaps a little more beginner friendly solution is to use the POINT OBJECT() and MOVE OBJECT commands. Using hero and object to identify the player and objects:




Enjoy your day.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 16th Apr 2009 23:31
Or even simpler...


can't read?
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 16th Apr 2009 23:38
True, but the dog won't face the man

Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 17th Apr 2009 03:42
yes and also that means if u draw a line on an imaginary "grid" that represents the dogs movement then that line could only have a slope of 1 or -1, meaning it wouldnt necessarily move "towards" the man persay

There are only 10 kinds of people in the world, those who understand binary and those who dont
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 21st Apr 2009 08:18
Good catch latch!

I only thought of the unit vector because that is all I have been doing in my Statics course for the last few weeks.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose

Login to post a reply

Server time is: 2025-06-08 05:44:18
Your offset time is: 2025-06-08 05:44:18