Sign in to follow this  

need some math help with continuous rock-paper-scissors

This topic is 3728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm making a turn-based strategy game. There are going to be 20 regular unit types and 60 hero classes and I need to be able to specify how the unit vs unit part of the matchup works. I have a lot of math for different aspects of the battle but I am missing one key piece. I need a smooth, trig-like function that falls on the following points: (0,0) (2n,m) this is the maximum (3n,0) (4n,-m) this is the minimum (6n,0) this is where the function repeats; this is (0,0) By comparison the sin function works like so: (0,0) (n,m) (2n,0) (3n,-m) (4n,0) and if you realize that 6n in my function equals 4n in the sin, well then my function is like a sin but the maximum is at 120 degrees rather than 90, and the minimum is 240 rather than 270. So I was thinking that the solution would look something like so: y = sin(f(x)) so what is f?

Share this post


Link to post
Share on other sites
I don't think that's a sinusoid wave, it's just a repeating one. I don't think there's anything close to a simple sin function to get what you want. However, I bet you could make a piecewise function to do what you need:


float repeatingWave(float N) {

if N >= 6 { N-= 6; }

if N >=0 && N <= 2 { f = m * sin(N * w1); }
if N > 2 && N <= 3 { f = m * sin(N * w2 + phase1); }
if N > 3 && N <= 4 { f = m * sin(N * w1 + phase2); }
if N > 4 && N <= 6 { f = m * sin(N * w2 + phase3); }

return f;
}


I'm not really up to figuring out the exact values of the various w's and phase's at the moment, but this should get you started:

sin(0 * w1) = 0 && sin(2 * w1) = m: solve for w1

sin(2 * w2 + phase1) = m && sin(3 * w2 + phase1) = 0: solve for w2 and phase1

sin(3 * w1 + phase2) = 0 && sin(4 * w1 + phase2) = -m: solve for w1 and phase2

sin(4 * w2 + phase3) = -m && sin(4 * w2 + phase3) = 0: solve for w2 and phase3

Five unknowns over eight equations shouldn't be difficult. Hope that helps

edit: removed stuff at beginning that basically repeated what was in your post

Share this post


Link to post
Share on other sites
Requirements:

1- (0,0)
2- (2n,m) this is the maximum
3- (3n,0)
4- (4n,-m) this is the minimum
5- (6n,0) this is where the function repeats; this is (0,0)

This function could be a starting point though it does not match exactly your requirements 2 and 4.

y = sin( x - sin(x) )

Share this post


Link to post
Share on other sites
First, let's say g(x) = f(nx), or equivalently, g(x/n) = f(x), just to get the n out of the way.

g(0)=0
g(2)=1
g(3)=2
g(4)=3
g(6)=4

Now any function that satisfies these properties will meet the requirements, but you probably want a smooth function. Just fit some sort of spline to these points (maybe even a linear one would be good enough). To make it cyclical, use the function x-6*floor(x/6). This describes a sawtooth wave with a period of 6 and a height that goes from 0 to 6.

[Edited by - Vorpy on September 30, 2007 11:40:41 AM]

Share this post


Link to post
Share on other sites
thanks everyone, I found a function that works well enough:

y = sqrt(3)*sin(theta) / (2+cos(theta))

basically I looked at how the sin was defined on the unit circle, and then I turned it into an ellipse so that the tallest part of the ellipse was to the left of the origin.

Share this post


Link to post
Share on other sites

This topic is 3728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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