moveLinear

Create fast, sprite powered games with Animation Engine, co-developed with DerBrill Software!

Moderators: heatherlaine, kevinmiller, robinmiller, malte

Post Reply
edljr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 56
Joined: Sun Oct 26, 2008 6:47 am
Location: Tullahoma, Tennessee, United States
Contact:

moveLinear

Post by edljr » Sun May 31, 2009 10:39 pm

I am new to AE (purchased it 9 days ago) and am having fun experimenting. I have a quick question regarding the moveLinear function.

The game I am working on has several user-controlled objects; if any of them enter an 'enemy zone' its short ID is sent to a "tellEnemy" function. That function invokes the "enemyDetected" command for all visible robots.

Here is the code for my "enemyDetected" command:

Code: Select all

on enemyDetected
   global whatToKill
   local mySpot, enemySpot
   
   put the loc of me into mySpot
   put the loc of img ID whatToKill into enemySpot
   -- get close enough to fire
   repeat until distance(mySpot, enemySpot) < 100
      set the moveLinear["startpoint"] of me to mySpot
      set the moveLinear["endpoint"] of me to enemySpot
      moveLinear
      -- location refresh
      put the loc of me into mySpot
      put the loc of img ID whatToKill into enemySpot
   end repeat
   // attack
   put the short ID of me into myName
   get attack(whatToKill, myName)
end enemyDetected
Of note, I have not worked on the "attack" function yet, but that is next.

Okay, now for my questions.
(1) How do I control the speed in which the robots approach the enemy? Currently, it is unrealistically fast.
(2) How do I ensure the robots do not land on each other?

Thanks in advance,
Ed

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Post by malte » Mon Jun 01, 2009 2:33 pm

Hi Ed,

I'd suggest you take a look at aeMoveTo you can controll this command with a time it shoulld take and it handles all the timing by itself. moveLinear, though still useful in some situatios is a predecessor of aeMoveTo. For the overlaping robots you can check for an intersect (this would be a bounding box check provided by rev) and if you need more precission use aes collision detection functions after you get a true from the intersect function

If you need any details in code let me know and I'll try to whip p something.

Cheers,

Malte

edljr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 56
Joined: Sun Oct 26, 2008 6:47 am
Location: Tullahoma, Tennessee, United States
Contact:

aeMoveTo

Post by edljr » Mon Jun 01, 2009 11:11 pm

Hi Malte,

Thanks for the lead...aeMoveTo did the trick!

I am really enjoying AE; it is a great time saver.

Ed

Post Reply

Return to “Animation Engine”