Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How so I make a laser path prediction line like a “slingshot cowboy” game in cocos2d or box2d and select the target like "slingshot cowboy" game.

share|improve this question
1  
I'm sure I'm the only one who doesn't know what slingshot cowboy is, I'm so out of the loop. But perhaps you can edit your question to explain the effect your talking about, beyond relating it to slingshot cowboy? Maybe an image and a paragraph? –  Byte56 Jul 27 '12 at 14:09
    
Me too, What the hell is "slingshot cowboy" game:D? –  wanting252 Jul 27 '12 at 14:14
    
I guess a cowboy using a slingshot instead of a colt revolver isn't the explanation. Probably a drag touch input like in angry birds and the prediction should be the dotted trajectory line, but the OP has to answer. –  teodron Jul 27 '12 at 14:18
    
I know, I'll gis "slingshot cowboy" in order to see this laser prediction line a2.mzstatic.com/us/r1000/066/Purple/v4/f6/06/46/… –  jhocking Jul 27 '12 at 14:25
1  
It's all laser slingshot wielding cowboys fighting zombie cow sharks nowadays... –  bummzack Jul 27 '12 at 18:20
show 1 more comment

1 Answer 1

Let's consider the basic slingshot mechanism that seems to be implemented here. enter image description here We know the user can drag the slingshot by defining a vector having its origin at the tip of the downward pointing triangle (like in my figure). The user can define thus vectors that point toward the bottom of the screen (restricted programmatically), and whose radii cannot be larger than a dMax threshold.

Whenever the user shoots, the input vector has a length between [0, dMax]. This interval must map into a range interval: [rNear, rFar].

But since the range in real life is usually not a linear function of the launch velocity, we're free to suppose that the transfer function between [0,dMax] and [rNear,_rFar_] is looking somewhat like this:

 rangeFunction(l) = (rFar - rNear) * sqr(l / dMax) + rNear

where rFar is the maximum range (the red circle's radius), rNear is the minimum range (the green circle's radius). This function just maps one interval to the other, in a non-linear fashion. I'm using now the sqr (x^2) function for below unit positive values. This function should give the user that plausible natural impression we're looking for in such games.. without a lot of mathematics/physics to support it.

In the figure above, the red vector is the one that gives you the shooting direction: just normalize it (divide it through its magnitude) and negate it (add the minus sign to it). Then multiply it with the result from the rangeFunction(length) where the length is the initial length (before normalization) of this vector.

Now find the angle between the blue and red vector using a 2D cartesian frame and the atan2 function. Let this angle be u.

The point where the projectile will land should be _(r*cos(u - pi), r*sin(u - pi))_, where r = rangeFunction(length). That should be it, more or less. Check if this point is "inside a cow's aura" and then kill it, like cowboys are supposed to, right?

share|improve this answer
    
Thanks for helping me –  android creative Aug 15 '12 at 12:36
1  
@androidcreative There is a button with an arrow pointing up by the top of the answer. Pushing it will demonstrate your everlasting gratitude. –  ClassicThunder Sep 25 '12 at 16:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.