2017-07-19 21:12:27

So here's the goal.  Before the ball is struck, the player should be able to set the targeted angle which he wants the ball to travel.  In other words, there will be a key to press, and then by hitting the arrow keys, a sound will move from left to right, changing the position, the angle as it were.  So instead of hitting the ball exactly diagonally, (1,1, 2,2, etc), they might choose an angle that doesn't go straight, but doesn't go exactly diagonally.  Maybe the angle means that it would travel more along the Y axis, while still travelling X, just less than it would diagonally., so more straight than left or right.  Or maybe the angle is sharper than diagonally, so more horizontally than straight.  What would be the most efficient way to handle this?

2017-07-19 23:02:41

Using trigonometry to handle the movimentation function.

2017-07-19 23:15:19

Trig with doubles for the position. If you need to use integer precision for the UI, you'd have to round.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2017-07-20 00:58:09

@CAE, whats the disadvantages on rounding the new values of the vectors?

2017-07-20 02:53:31

I would only round them for i/o, since you'd otherwise lose precision and get undesired behavior. You'd probably want to round elsewhere for readability, since the user mostly cares which integer square the object is mostly in, and not if it's really at 1.743981.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2017-07-20 09:49:41

Yes of cource, for handling movements based on angle i understud how can i do it with the aprone's coding tutorial, but my problem is playing sounds when the player moves exactly 1.0 from their previous location that the footstep sound was eard, for example every 1.0 that any axis increases. You know any math formula to handle it?

2017-07-20 11:11:04

There are a few ways. If the position is a vector, you can store its length before the movement, and compare it to afterward. Or you can keep track of the distance traveled, and when it reaches 1.0, play the sound then.
You can tell when the integer part of a double has changed multiple ways, such as if(floor(oldDistance)!=floor(newDistance)).

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2017-07-20 21:20:57

Thank you, i haven't think on it, and magnitude also works on this case?

2017-07-21 04:42:05

Yeah, the magnitude and the length are effectively the same, for these purposes.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2017-07-22 04:06:39

Aprone's coding tutorial?  Where is it?  Never saw it.

2017-07-22 04:45:54

http://forum.audiogames.net/viewtopic.p … 58&p=2

2017-09-11 10:58:33

CAE, i was thinking on several ways to handle that kind of behaviour on movimentation, but how did you made footsteps on JLA sound every 1.0 tiles based on player's speed?

2017-09-11 15:30:04

I  don't remember which of round, floor, or ceiling I used for this. I think it was round. I guess the other thing is that, when I'm having something move, I keep the old variables unchanged until the move is confirmed, and use temporary variables for the target position. So it's simple in this case to say if(round(x, 0) != round(tx, 0)) play_footstep(tx, ty); .
If you're doing this with top down or first person or 3d, you'd need to compare the lengths of the vectors instead, otherwise you'd get steps sounding much different when the player moves diagonally. I think that Swamp had this issue for one version early on.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.