Wavy Movement

I want my actor to move back and forth in a wavy like pattern. How do I do this?

To reiterate, this needs the option of working horizontally and vertically back and forth.

Alexin

  • *
  • Posts: 3132
Use sin or cos. Make the angle a function of the direction of movement.
"Find the fun"
alexin@stencyl.com

Epic428

  • Posts: 1118
y=sin(x)
x=cos(y)

If I am remembering my trig properly that should work.

you'd want to look up parabolas and parabolic equations.

Edit: or this http://en.wikipedia.org/wiki/Sine_wave
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

Epic428

  • Posts: 1118
because you have to increment/decrement x/y depending on the wave
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

Hectate

  • *
  • Posts: 4643
Here's an example from this tutorial

Code: [Select]
velocity.x = -200;
velocity.y = Math.cos(x / 50) * 50;
It makes the aliens move in a wave up-down pattern (Sine wave) where the speed of up/down is determined by their X position on the screen. An implementation of it is both in the tutorial as well as a modified version from a game I made using the tutorial.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Epic428

  • Posts: 1118
I remember that tutorial. That is a much better implementation.
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

Epic428

  • Posts: 1118
* 50;   this should control the Amplitude if I am not mistaken.

x / 50   this should control the Wavelength.
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

Epic428

  • Posts: 1118
That should be the amplitude if I am not mistaken, basically it shows the +/- tolerance for its height above and below its relative 0.

For example, and I could be wrong, if you do

velocity.y = Math.cos(x / 50) * 50;

then the waves will be close together, but the height of the wave will be +50px or -50px for its relative 0 (the Y it initially started on)

Changing the value inside the cos() determines the wave length

Edit: in case you didn't read the article on Sine Waves:



    A, the amplitude, is the peak deviation of the function from its center position.
    ω, the angular frequency, specifies how many oscillations occur in a unit time interval, in radians per second
    φ, the phase, specifies where in its cycle the oscillation begins at t = 0.
        When the phase is non-zero, the entire waveform appears to be shifted in time by the amount φ/ω seconds. A negative value represents a delay, and a positive value represents a "head-start".


Though, this is a bit more complicated than what you are doing, but it basically shows you more in depth what the values are when doing a sine wave

« Last Edit: April 23, 2011, 11:43:34 am by Epic428 »
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

Epic428

  • Posts: 1118
well when moving horizontally, you need to check it's x location, and change directions based on its location

Edit:
http://www.stencyl.com/v10/help/viewArticle/41
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

Rob

  • *
  • Posts: 1268
I just uploaded a wavy movement behavior to Forge that I make a few years back. You probably still need to tune it a little bit when it comes to collision. Try to set different x and y speed and period and you'll see the effect.

It's under SF->Behaviors->Newest->wavy movement.

Thx.
GOLDEN RULE #1 : SAVE YOUR GAMES FREQUENTLY
IOS/XCODE DEBUGGING
http://www.stencyl.com/help/view/xcode-ios-troubleshoot/
WATCH STENCYLWORKS VIDEO TUTORIAL BY SUNRISEKINGDOM
http://www.youtube.com/watch?v=KDfRfjzr9j4&feature=channel_video_title