Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 following a path? help please :D!
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
munt4life




PostPosted: Mon May 02, 2011 6:20 pm   Post subject: Re: following a path? help please :D!

it seems im just trying to jget the atleast attraction to work for now :p, perhaps later ill try to add such a feature, for now just the chasing is good without obstacles Razz
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Mon May 02, 2011 6:59 pm   Post subject: RE:following a path? help please :D!

ok, well here's a simple explanation:

Step 1: Find angle
Use arctand ((enemyy - y) / (enemyx - x)). Remember that it changes depending on whether or not the character is above or below the enemy. I would just use something like:
if x > enemyx then
angle := angle + 180

Step 2: Find vx and vy (the amount x and y change)
Easy enough. The formula is:
vx := speed * cosd (angle)
vy := speed * sind (angle)
Then you add those to x and y.

Again, that's a simple explanation. Try to use it, and ask if you have more questions about it. Or someone can try and give a better explanation:P
munt4life




PostPosted: Mon May 02, 2011 7:17 pm   Post subject: Re: following a path? help please :D!

what do you mean add to x and y?
munt4life




PostPosted: Mon May 02, 2011 7:19 pm   Post subject: Re: following a path? help please :D!

also, yeah i got that much it was just the actual movement of my rectangle( which in this case is the enemy ) that i wanted to move
so i got to the part you got too except im not sure what to put into the drawfillbox(????)
Raknarg




PostPosted: Mon May 02, 2011 7:28 pm   Post subject: RE:following a path? help please :D!

oh... ok
You set x and y like so:

x := x + round (vx)
y:= y + round (vy)
Draw.FillBox (x, y, ?, ?, ?)

You can set those last three parameters to whatever you need.
Also, the vx and vy are positive or negative depending on where they are compared to x and y. Such as:

if x < enemyx then
vx := -speed * cosd (angle)
elsif x > enemyx then
vx := speed * cosd (angle)
end if
munt4life




PostPosted: Mon May 02, 2011 7:57 pm   Post subject: Re: following a path? help please :D!

+10 bits thanks alot Very Happy
munt4life




PostPosted: Mon May 02, 2011 8:03 pm   Post subject: Re: following a path? help please :D!

haha i asctually just got away with the really simple method of

drawfillbox (compx, compy, compx + 10, compy + 10, red)
if (compx < x) then
compx += 5
end if
if (compx > x) then
compx -= 5
end if
if (compy > y) then
compy -= 5
end if
if (compy < y) then
compy += 5
end if
Raknarg




PostPosted: Mon May 02, 2011 8:05 pm   Post subject: RE:following a path? help please :D!

XD Yeah, that works too. It's only if you want realistic movement. That works fine.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 23 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: