The Daily Click ::. Forums ::. Klik Coding Help ::. What's the equation to make something levitate in air?
 

Post Reply  Post Oekaki 
 

Posted By Message

eyeangle



Registered
  12/06/2003
Points
  1683
26th February, 2008 at 19:40:39 -

I need an object- 40x40, to float up and down a few pixels in mid air. I've tried path movment but it's not smooth.

Cheers.

 
theonecardgame.com

Ski

TDC is my stress ball

Registered
  13/03/2005
Points
  10130

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!KlikCast HelperVIP MemberWii OwnerStrawberryPicture Me This Round 28 Winner!PS3 OwnerI am an April Fool
Candy Cane
26th February, 2008 at 19:43:17 -

"Wingardium leviosa"

I'm sorry I couldn't help myself

 
n/a

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14586

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
26th February, 2008 at 20:07:37 -

I don't think many people use equation for that, they just use animations... don't they? Well i would.

 
.

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
26th February, 2008 at 20:21:20 -

i can do this without an animation but require one alterable value and one flag!!!!!

you got the goods?...

 
n/a

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
26th February, 2008 at 20:36:50 -

Well my dear, what you require is the use of "sin" or "cos"

these 2 deviate between 1 and -1 as the value increases.

Example would be

Object => Set Y position to (Y co-ordinate to deviate from) + (max pixel deviation)*sin(x)
for 0<=x<=360
anything outside this range is obsolete, as the pattern is symmetrical.

The max pixel deviation is how many pixels you want it to go up or down by.

However, do note that decimals will occur, so if it appears jumpy, you're not compensating for decimal values. (you also cannot have a fraction of a pixel)


 
My signature is never too big!!!

nim



Registered
  17/05/2002
Points
  7234
26th February, 2008 at 20:45:59 -


Originally Posted by cec¿l
i can do this without an animation but require one alterable value and one flag!!!!!



Is that a problem? Don't be afraid of alterable values You'll probably need to use at least one to get the effect you want here.

The best solution (in MMF2) I can think of is:

Always > Set Y to 200+(Sin(timer/2)*3)

where 200 is the Y coordinate you want it to hover around, /2 slows it down, and *3 increases the wave height. If you're creating the object in a location that's not fixed then you'll have to set an Alterable Value to the initial Y coordinate instead of using 200.

 
//

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
26th February, 2008 at 20:46:08 -

my demands have increased. i will now require 2 actives, 2 alt variables, and one flag. its smooth but id go with the trig.
but i must say i quite like the way it looks sitting there, all floaty like.

 
n/a

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
26th February, 2008 at 20:47:21 -

it isnt a problem its just my demands!!! MWUAHAHAHA

 
n/a

nim



Registered
  17/05/2002
Points
  7234
26th February, 2008 at 20:49:34 -

I can't imagine what you're using the flag for, but I guess we all have our own way of doing things..

 
//

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
26th February, 2008 at 20:56:44 -

well im not using trig. so the flag is for whether it goes up or down.

the extra active is just so it has a place to hover around. in my case i just made it a cube and a shadow. the cube hovers above the shadow.

and i got rid of the extra alt.

 
n/a

nim



Registered
  17/05/2002
Points
  7234
26th February, 2008 at 21:14:01 -

If you have a shadow object then perhaps you could try:

Always > Set Y("floaty") to Y("shadow")-100+(Sin(timer/2)*3)

No alterable values or flags required.

 
//

eyeangle



Registered
  12/06/2003
Points
  1683
26th February, 2008 at 21:16:56 -

Thanks guys but nim sold it in a perfect equation: Always > Set Y to 200+(Sin(timer/2)*3)

But I mean, seriously, how did you figure that out!?

 
theonecardgame.com

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
27th February, 2008 at 00:28:45 -

its simple highschool math edwin. sin or cos functions are waves. as x increases or decreases to infinity y increases and decreases between 1 and -1. its cyclic so it goes on forever. how would he NOT figure that out?

the only problem i have with it is what he mentioned. it appears jumpy because of decimal values of you dont compensate.

 
n/a

Dustin Gunn

Gnarly Tubular Way Cool Awesome Groovy Mondo

Registered
  15/12/2004
Points
  2659

Game of the Week WinnerKlikCast StarVIP MemberI'm on a BoatGOTW Winner Oct 2010Kliktober Special Award Tag
27th February, 2008 at 05:46:28 -


Originally Posted by Edwin Street
Thanks guys but nim sold it in a perfect equation: Always > Set Y to 200+(Sin(timer/2)*3)

But I mean, seriously, how did you figure that out!?



Learn sin and cos well, they're the most useful math functions for games ever

 
n/a

Deleted User
27th February, 2008 at 14:53:39 -

Cecil, it appears jumpy because you're using the timer as a counter (which is independent from the frame rate), not because decimals are not being "compensated". And it would appear jumpy if you multiply the radius by 40+. Otherwise, it looks smooth.

 

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
27th February, 2008 at 15:32:09 -

well im not using the timer. nim is. im not even using trig. =P
and i was just repeating what not clubsoft said.

but yes. in tgf it will be jumpy (or in my opinion probably doesnt work at all without advanced math object and a decimal offset) because of decimals regardless of the timer.

redirect and improve your rebuttle sir. =\

btw. how is heart forth alicia coming?!

Image Edited by the Author.

 
n/a

nim



Registered
  17/05/2002
Points
  7234
27th February, 2008 at 17:01:20 -


Originally Posted by cec¿l
well im not using the timer. nim is. im not even using trig. =P



Cecil, maybe you'd like to explain your situation more, or start a new thread, because the solutions posted here were in response to the original question by Edwin. I'd be interested to see how you're doing this without trig (and why..)

For the record, TGF doesn't have any trig functions. I don't even know if it includes the "timer" function. So yes, you'd have to use the Advanced Math Object.


 
//

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
27th February, 2008 at 17:29:16 -

well a new thread is highly unnecessary.
its basically 5 events. 4 active specific events and 1 always event

ill base it around a single y point to get rid of the second active (shadow) im using.

+always => set y("active") to 200 - Value A("active")/5
+flag0 is on => add 1 to Value A("active")
+flag0 is off => sub 1 to Value A("active")
+Value A("active") > 75 => set flag0 off
+Value A("active") < 25 => set flag0 on

that makes it float around the y coordinate of 200 at a nice speed (thats where the divide by 5 comes in) smoothly.

timer IS in tgf. timer count in 1/1000 sec 1/100 sec seconds minutes and hours since the start of level.

and why not?
if you can do it without trig or extensions in very few events and vars then more power to ya...me...

i would highly recommend the trig way tho.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click