Advertisement

Moving diagonaly how to calulate from horizontal and vertical speed

Started by September 03, 2013 12:51 PM
16 comments, last by BaneTrapper 11 years, 4 months ago

Wish i could respond to you all, but you all are sharing one point.

Also i am not using vectors or any kind of ADV math.

I should:

Object has "Movement rate" at witch rate it moves. Objects can move horizontal, vertical, diagonal.

If moving horizontal or vertical movement rate is always flat, if moving diagonal then i just substract movement rate by /2

int diagonalMoveRate = moveRate / 2;

I could have just told you to flip "* 2" in the calculation to "/ 2"

Brilliantly explained with little said.

If you want to move diagonally at the same speed as vertically or horisontally you need to use 1/sqrt(2) as a multiplier. As an example you want to move up and right at the same time you would increase the units y and x coordinate by speed/sqrt(2) and while moving vertically or horisontally just increase y or x by speed without the multiplier. But if you want it to take as long to move diagonally as it would take to move horizontally and vertically in sequence you propably don't want to allow diagonal movement at all. Also if you are using limited hardware like mobile devices usually are. You should calculate sqrt(2) at the start of the program and use the precalculated value as calculating square roots can be demanding. Especially if the device does not have hardware floating points. PS. 1/sqrt(2)=sin(45degrees)=sin(PI/4radians)~=0.70710678118654752440084436210485
Advertisement

I know all of you mean well with thorough explanations but in the end you'll just confuse him with the fancy math.

I am trying to achieve that if a unit is moving 10sec horizontally then 10 sec vertically to be same position as unit moving 20 sec diagonally.


int diagonalMoveRate = moveRate / 2;

That is wrong, physically / mathematically. Moving diagonally is supposed to be more efficient than moving one direction and then another. If you move diagonally the distance is shorter than taking the indirect route. This would be right:


int diagonalMoveRate = moveRate * 0.707;

There, fast and efficient and accurate enough. Sure you can use 0.70710678118654752440084436210485 if you think it matters for your game. If you want to know why, read all of the posts above again and study Pythagorean theorem, geometry, vectors etc. until you understand smile.png

I know all of you mean well with thorough explanations but in the end you'll just confuse him with the fancy math.

I am trying to achieve that if a unit is moving 10sec horizontally then 10 sec vertically to be same position as unit moving 20 sec diagonally.


int diagonalMoveRate = moveRate / 2;

That is wrong, physically / mathematically. Moving diagonally is supposed to be more efficient than moving one direction and then another. If you move diagonally the distance is shorter than taking the indirect route. This would be right:


int diagonalMoveRate = moveRate * 0.707;

There, fast and efficient and accurate enough. Sure you can use 0.70710678118654752440084436210485 if you think it matters for your game. If you want to know why, read all of the posts above again and study Pythagorean theorem, geometry, vectors etc. until you understand smile.png

I get what you are talking about.

Walking 10pixel right then walking 10 pixel down = 20 pixels, but walking diagonally from same start position to same end position != 20pixels.

You all talking about different things guys

Author gave us rule

"I am trying to achieve that if a unit is moving 10sec horizontally then 10 sec vertically to be same position as unit moving 20 sec diagonally."

so its

int diagonalMoveRate = moveRate / 2;

If author want to move the same speed horizontal, vertical and diagonal

so its

int diagonalMoveRate = moveRate / sqrt(2);

I'm curious. Is this a game with bizarre physics. Is it some sort update check you're working on where diagonal movement is crippled? Please tell us more about this movement, it seems very different from the norm.

I've read about the idea guy. It's a serious misnomer. You really want to avoid the lazy team.

Advertisement

This is an old topic, last reply by author 4th September before serumas dug it up 20 days later from page 5.

It is also resolved as far as I can tell, why don't you just let it sink?

I'm curious. Is this a game with bizarre physics. Is it some sort update check you're working on where diagonal movement is crippled? Please tell us more about this movement, it seems very different from the norm.

The game is top down 2d survival / action game with crafting, mining(terraforming), hunting - surviving, battling...

I just felt need to make diagonal movement slower then linear(horizontal or vertical).

To make sense:

If moving upwards 10 seconds you moved X distance

If moving diagonal 10 sec you should move X distance as well

This is an old topic, last reply by author 4th September before serumas dug it up 20 days later from page 5.

It is also resolved as far as I can tell, why don't you just let it sink?

By the hobgoblin law that will not be allowed!!!

(Hes just lucky i loged in smile.png )

This topic is closed to new replies.

Advertisement