Cos and Sin math problem (custom 8 direction)

Okay, well I'm still trying to fix my 8 direction movement.

I guess I'm not understanding the Cos and Sin math right? The problem is that the character appears to be moving at angles faster than up, down, right, left. Here's what I have going on:

Repeat While Moved Right

* X( "Player Movement" )+Player Speed*Cos(0)

* Y( "Player Movement" )-Player Speed*Sin(0)

And so on for each direction (replacing 0 with the appropriate angles.

What am I doing wrong? Yes, I know I'm not good at math :P

Re: Cos and Sin math problem (custom 8 direction)

To clarify "Player Movement" is the player object, and Player Speed is a global value for adjusting the speed of the player (obviously).

Re: Cos and Sin math problem (custom 8 direction)

Shawn,

I'm not entirely sure I understand what you are trying to do, but I will upload a screen from a game I'm working on called Asteroids (perhaps later to be called ROIDS. I've got a space ship that you can accelerate in the direction you are pointing and there are counters that calculate the x and y acceleration, velocity, and distance. It's a little cluttered since I've been playing with a number of other possible options, but it might help you get what you want to do done.

Steve

Re: Cos and Sin math problem (custom 8 direction)

Quote:

Originally Posted by **drnebula**

Shawn,

I'm not entirely sure I understand what you are trying to do, but I will upload a screen from a game I'm working on called Asteroids (perhaps later to be called ROIDS. I've got a space ship that you can accelerate in the direction you are pointing and there are counters that calculate the x and y acceleration, velocity, and distance. It's a little cluttered since I've been playing with a number of other possible options, but it might help you get what you want to do done.

Steve

Well, what I'm just trying to create a basic 8 direction movement. Similar to the built in one, but just so I can customize it more.

But here's what I have so far, in a better explanation:

I have:

Repeat while holding left:

Set X coordinate of Player to Player's X Coord + Speed * Cos(180)

Repeat while holding right:

Set X coordinate of Player to Player's X Coord + Speed * Cos(0)

Repeat while holding Up

Set Y Coordinate of Player to Player's Y Coord - Speed * Sin(90)

Repeate while holding Down

Set Y Coordinate of Player to Player's Y Coord - Speed * Sin(270)

These events let me move in 8 directions, but it's not calculating the angles right and I don't know how to do that. Unless I'm hallucinating, it seems like when I move in the angled directions, you move just a bit faster. I tried solving this a while back but got stuck.

I tried adding the 45 degree angles for up+right etc. but that just created even more problems.

Re: Cos and Sin math problem (custom 8 direction)

Well i've been reading about vectors and things online, and I read something about how I'm supposed to be using radians and not degrees with cos and sin? I have no idea how to do that in mmf.

Re: Cos and Sin math problem (custom 8 direction)

The sin and cos funtions in MMF work just fine with degrees. No need to mess around with radians.

Steve

Re: Cos and Sin math problem (custom 8 direction)

I don't have time to look at this right now, but for the Repeat while holding left, it would be: SEt X coordinate of Palyer to Players X Coord + Speed (no Cos(180) needed). For the four up, down, right, and left, just take out the sin or cos. They are not necessary. You only need the sin(45) when you are moring in both directions simultaneously.

Steve

Re: Cos and Sin math problem (custom 8 direction)

Okay cool thanks! I'll start messing around with it when I get some time and see what happens lol.

Re: Cos and Sin math problem (custom 8 direction)

I put an example of a home made 8 direction motion compared to MMFs 8 direction motion and they are pretty much identical.

Now, if you push the right and up buttons, the object will go both right and up at the same speed, which is not what would happen in the "real" world. If that is what you want, then you would need to change the speed in all of these directions to sin(45)=cos(45)=0.707*speed.

Hope this helps.

Steve

Re: Cos and Sin math problem (custom 8 direction)

Yes, I'm trying to get the object to not travel faster when going in angles, which means I'm going to have to multiply by 0.707.

However, I need some clarification of this line:

"sin(45)=cos(45)=0.707*speed"

I tried multiplying the speed by 0.707 for the angled directions and it produced weird results.

At this point, I have the 8 directions working, I just need the vector movement right, which is where the 0.707 comes into play. I'm apparently not putting the expression in correctly in MMF.