• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Ilmiont

Making simple floating/drifting animation

6 posts in this topic

Hello all,

 

I'm a bit stumped creating something realistic.

 

We've all been to the sea and noted that little bit of seaweed gently floating around in the water... never really getting anywhere, just aimlessly moving back and forth.

 

How could I recreate that in code? Specifically, for a jellyfish controlled by the player so you can move it, slowly, but when you're not moving its just "floating" about. Ideas?

 

Thanks in advance,

Ilmiont

1

Share this post


Link to post
Share on other sites

What about a time-based function which calculates a sinus-waveform?

You can then add its output to your jellifishs' x and/or y coordinate whenever you are not moving it yourself. (you maybe have to scale the output for both axis differently so it looks nicer)

 

Regards

Markus

0

Share this post


Link to post
Share on other sites

Woah, sorry I'm lost. I'm not too hot on the maths stuff, is it possible you can explain it in simpler terms? *Heads to Google* :)

0

Share this post


Link to post
Share on other sites


What about a time-based function which calculates a sinus-waveform?

 


Woah, sorry I'm lost. I'm not too hot on the maths stuff, is it possible you can explain it in simpler terms?

 

this is one common way to do it.   in fact, it might qualify as a "game design pattern" ! <g>.

 

a simple example:

 

lets say your jellyfish's position is given by x,y,z.

 

then you have a frame counter, or timer, that increments over time, giving you an elapsed time value et.

 

to make the jellyfish "float", you calculate the jellyfish's final position as:

 

x_final = x+sin(et)

y_final = y+sin(et)

z_final = z+sin(et)

 

to mix it up a bit, in some of the formulas you can use cos() instead of sin(), you can multiply et by a constant, and/or multiply sin(et) or cos(et) by a constant.

 

sin() and cos() will be 1/4 cycle out of phase with each other. multiplying ET by a constant will shift the phase of the wave. multiplying sin(et) or cos(et) by a constant will change the amplitude of the floating action (change how far it moves back and forth).

 

you'll probably want to multiply sin(et) or cos(et) by the same or similar values, so it floats about the same amount in all directions.

 

mixing it up a bit you might end up with something like:

 

x_final = x + c1 * sin(et * c2)

y_final = y + c1 * cos(et * c3)

z_final = z + c1 * sin(et * c4)

 

where c1 through c4 are constants whose values are determined by experimentation.

 

 

 
1

Share this post


Link to post
Share on other sites

And to make it look a bit more realistic, you can add together several sin-waves with different frequency and amplitude.

 

something like this:

 

x_final = x + a1 * sin(et * f1) + a2 * sin(et * f2) + a3 * sin(et * f3) + ... 

 

Though, in code, this is best done in a for loop, then you can add a bunch of them together.

 

The biggest amplitude and frequency constants is the most important to tweak, then you can calculate the rest by random subdivision. ( get random value between 0.3-0.7 (or something), then calculate f2 = f1*rand_value, and so on) 

 

Edit: Actually, for each step, you want to increase the frequency, but decrease the amplitude. So you get longer big waves, mixed with shorter small waves.  so for each step multiply the f-values with a random value around 2, and the a-values with a random value around 0.5

Edited by Olof Hedman
1

Share this post


Link to post
Share on other sites

Notice that the sine functions takes radians.  That means a full rotation, or period is 2*PI radians.  That again means that if you want 360 steps before completing a full circle, or period, you need to divide by 360.

 

So 360 steps per second, with time t and amplitude 10 will be:

(Edit: 360 steps per second would mean 1/360 seconds per step, and you would still have one revolution per second)

position = x + 10 * sin(t * ((2 * pi) / 360))

For the other dimensions, y and z, you may perhaps want to have another phase, which is just to add a value between 0 and 2 * PI inside the sine function.  This prevents the wiggling to be on a line in the space or plane you want to move.

 

 

If you want to have a certain amounts of wiggles per second, you can instead just multiply with 2 * pi instead, like this:

position = x + 10 * sin(t * 2 * PI * wiggles)

If wiggles is 10, you will have 10 wiggles per second, if wiggles is 1/2, you will have half a wiggle per second.

 

The general function is:

f(time) = offset + amplitude * sin(time * 2 * PI * frequency + phase)
Edited by aregee
1

Share this post


Link to post
Share on other sites

Lol this feels like another perlin like conversation :)

Gotta love waveform based math ... so not easy !!!

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0