Question: How to rotate an object?

mutazoid

Member
Im thinking GML has an easy solution to this.
The example gamemaker gives is to follow the mouse but I just want the object to rotate 90 degrees each time I click on it. (eventually Id like to do more but this is the starting point)

Thanks :D
 
S

Subdomain Games

Guest
Hey there,

if you want a smooth rotation instead of a quick snap use this code:

Code:
//CREATE EVENT
rspeed = 5; //the speed of rotation, how fast it rotates
Point_dir = 0; //the variable that will store what direction to rotate to
Is_Rotating = 0; //is it rotating, used in the STEP event to rotate the object

//LEFT PRESSED EVENT
Point_dir = image_angle + 90; //the angle to rotate to, add 90 degrees to current angle
Is_Rotating = 1; //set to true

//STEP EVENT
if (Is_Rotating == 1) //if its set to rotate the object
{
     image_angle += sin(degtorad(Point_dir - image_angle))*rspeed;
}
That will give you a smooth rotation from whatever angle you're currently facing + 90 degrees. :cool:
 
Last edited by a moderator:
S

Subdomain Games

Guest
Hmm I tried the smooth rotation but it doesnt do anything. Hmmm I dont see any error in the code.
Its my mistake.

change:

Code:
image_angle += sin(degtorad(point_dir - image_angle))*rspeed;
to

Code:
image_angle += sin(degtorad(Point_dir - image_angle))*rspeed;
I think the problem is with "point_dir", you probably initialized it with a capital "P" in the create event. Sorry. I'll edit the main post
 
Top