Hi!
So I have a problem understanding the maths: angles,rotation.
When I turn a player at a specified angle..I need to able to make the player move in the direction at which i am facing.
But apparently that is a big problem and i don't understand it..
I tried finding the new coordinates by using
angle = 0.0f; new_x = cos(angle) * radius ; new_y = sin(angle) * radius ; angle+=0.1f;//or minus depending on which key i am pressing(LEFT or RIGHT) rotate_sprite(..) ;
that should give me the new x and y direction for controlled player to move it..
But if I was to add the old vector to the new one..it could "jump" and will get stuck at the (0,0) corner of the screen.
First question I want to know is why is 0.0 the starting angle?
After studying tutorials on the website, they seem to neglect explaining this..it might seem basic to you but I don't understand maths
so why is angle set at 0.1f degrees and then incremented..or is it degrees or units?
do I have to convert to degrees to get the proper x and y values..i tried both and either it doesn't move or it gets stuck..
So how do I fix this?
How can I turn my player using the keys and the move in that direction
Can anyone draw a little diagram to help me understand this?
I understand better with that thanks.
But if I was to add the old vector to the new one..it could "jump" and will get stuck at the (0,0) corner of the screen.
That is what you should to do.
Without some actual code and a better description of what isn't working, there is nothing else we can do.
Sorry, my bad
vector2 just has x and y coordinates nothing more.
And are those coordinates integers or floats?
If your vector handling might be at fault (which has already been implied), it's probably a good idea to post your code for that too...
That is Vector.h and Vector.cpp combined..
but I am not using any member functions within the Vector class.
Everything is mainly procedural now..because I am trying to get sense of the maths..
In direction, it's better to use atan2(y, x) since that handles special cases.
And you know you can overload operators right?
Then you can do vector1 += vector2 instead of vector1.add(vector2), I think that's much nicer. Though it doesn't solve your problem.
i haven't gone past polymorphism haha
Yeah I have read of overloading an operator..but too advance at this stage..
i know i can use atan2(..) or sin(..) ...
but my question is how and when do I use them?
why is the angle set to 0.0f? why is it incremented?
Does angle represent degrees or is it just a simple unit?
How can i move the player object in the direction to which i am facing?
Thanks for help
why is the angle set to 0.0f
Because... you've initialized it to 0.0f?
why is it incremented?
Again, you are the one doing it.
Does angle represent degrees or is it just a simple unit?
How can i move the player object in the direction to which i am facing?
(Note: I have not looked at your code, since I haven't read a good enough explanation of what your problem is yet.)
mmn..
i have a point, a vector on the graph. x and y coordinates.
I want to be able to turn at a certain angle if i press left or right key, and move the player in that direction.
the last parameter takes a fixed angle. In some examples they use 90,64,128...some 0.0f
I have no idea where they get the value from, do I pick a random value to be my fixed angle and simply increment or decrement?
you give me this equation
which angle do I use?
angle I have set to rotate about
or another angle I have to find tan(y/x) ?
when do i use atan(y/x) ?
how come you aren't multiplying by magnitude?
Allegro uses fixed math for its directions. So 256 fixed is 360.0 degrees or 2*PI radians. The examples you're seeing are taking into account that 0..64 gives angles from 0..90 degrees (or 0..PI/2 radians) in order for things such as rotate_sprite() to allow the object to face in the correct direction.
There are two ways to do your movements. You can use cartesian coordinates (x,y) or polar (theta, magnitude). They will equal the same in the end, but lets you choose which math you want to use to get there.
I have used this diagram to try and explain the angle concept in allegro.
Can someone correct it if wrong?
The diagram is attached.
The player moves in the right direction only if its angle is between 0 and 64 degrees, after that it doesn't move in the right direction..
can someone help ?
Thanks
I'm suprised nobody's mentioned Amarillion's Legendary Sin & Cos Tutorial.
I read it already. I get how to convert from polar to cartesian and vice versa.
But it doesn't explain some basic stuff - which basic, i don't get -
like why is the initial angle set to 0, instead of 90 which makes more sense.
Even then there must be a bug in my code because the sprite does not move in the right direction..after 64 degrees
how come you aren't multiplying by magnitude?
I am. move_speed_per_tick.
rotate_sprite(backbuffer,playerOne,pos1.x ,pos1.y,ftofix(angle));
ftofix() only converts a float into fixed point - it doesn't change the angle representation. You're trying to pass in degrees (0-360) instead of allegro angles (0-256) to rotate_sprite().
angleallegro = angledeg*256/360.
As a general rule: keep all angles in radians. Only convert them to something else when a function for some reason expects something else (e.g. rotate_sprite() or glRotatef()) or when it needs to be displayed to the player in another format.
like why is the initial angle set to 0
... arrrgh. Because you fucking set it to 0.
If you wanted to, you could have an initial angle of 666 degrees, or ei*pi radians, or...
arrrgh. Because you ****ing set it to 0.
yes i know i set it to 0, what i don't get is
why is 0 degrees making the bitmap perpendicular<b>
That should be 90 degrees.
Is it the way allegro is set or something?
I tried multiplying by 256/360, and the sprite wouldn't move.
EDIT
OMG it is working now! I don't get it, before when I tried it didn't work!!!!
I understand calculating the angles and cartesian coordinates!
but still not why the initial angle is set to 0 which makes it face upward
but when i make it 90 degrees,it appears to be 60 degrees!