The Daily Click ::. Forums ::. Klik Coding Help ::. Oscillating enemy?
 

Post Reply  Post Oekaki 
 

Posted By Message

Trooper



Registered
  22/07/2002
Points
  597
7th November, 2004 at 14:03:02 -

Hi, I was wondering if any of you knew how to make an enemy go up and down periodically (just like a sin wave). I tried using the sin function and the timer to set its position but it tends to go up as it oscillates.
(( i used -- "set enemy y position = enemy y position + sin(timer)" ))

note - i have multiple enemies of the same kind so i want them to move independently of one another (they are created at certain intervals)

any ideas/help? =]

 
-Trooper-

X_Sheep

I had a custom rating before it was cool

Registered
  01/03/2004
Points
  1313

VIP MemberPicture Me This -Round 23- Winner!Dos Rules!
7th November, 2004 at 14:44:06 -

How bout this:

Start of level: Set Alterable value A to Enemy Y position.
Always: Set enemy Y position to Alterable value A + sin("timer") or something.

 
a/n

醤油の兵士

Almost Human

Registered
  12/06/2002
Points
  173

VIP Member
7th November, 2004 at 14:55:18 -

you might want to try multiplying the sin function in the function X_Sheep gave you, like AltA+Sin(timer)*10 (or however many pixels you want it to go away from it's normal position).

 
As a boy, I wanted to be a train. I didn’t realize this was unusual—that other kids played with trains, not as them.

Trooper



Registered
  22/07/2002
Points
  597
7th November, 2004 at 15:25:40 -

i tried those and it still does the same thing.. thanks anyways guys =]. maybe i wasnt clear in my explanation. as it oscillates up and down, the generally direction of the object goes up.. for instance, every pixel it goes down, it goes back up 2 pixels (eventually going off the screen)... its really weird. I think it has something to do with the decimal limits which messes up the sin function just a little. any other ideas?

 
-Trooper-

Jimmy Brzezicki



Registered
  16/09/2003
Points
  1057
7th November, 2004 at 15:33:43 -

The horror! I come here to escape from my Physics degree! Now you talk of that which I study day and night in wave phenomena! At least you're not asking about partial differentials. Your problem is that sin(anything)is less than 0 so nothing happens. Do set enemy Y position to value A (as the sheep suggested) +somethingxsin(timer) (eg 10xsin(timer))

 
Why the hell am I on the computer at 1 in the morning? No, don't answer.

Trooper



Registered
  22/07/2002
Points
  597
7th November, 2004 at 17:01:28 -

Thanks so much Sheep, Amnesiasoft , and Jimmy. This works excellent. =]

 
-Trooper-
   

Post Reply



 



Advertisement

Worth A Click