Question: How to rotate an object?

Discussion in 'Programming' started by mutazoid, Aug 14, 2016.

  1. mutazoid

    mutazoid Member

    Joined:
    Aug 14, 2016
    Posts:
    39
    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
     
  2. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    Hi and welcome to the GMC!

    Put in the mouse left pressed event:
    Code:
    image_angle += 90;
     
  3. mutazoid

    mutazoid Member

    Joined:
    Aug 14, 2016
    Posts:
    39
    oh duh heheh its been a while since I played with gamemaker.
     
  4. 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: Aug 15, 2016
    Shazard Bansraj likes this.
  5. mutazoid

    mutazoid Member

    Joined:
    Aug 14, 2016
    Posts:
    39
    Hmm I tried the smooth rotation but it doesnt do anything. Hmmm I dont see any error in the code.
     
  6. IndieCrypt

    IndieCrypt Guest

    Can you please further explain how this works please?
     
  7. 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
     
  8. Furious_pancake

    Furious_pancake Member

    Joined:
    Aug 20, 2017
    Posts:
    1
    how would you make it face where the mouse is?
     
  9. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,210
    Code:
    image_angle = point_direction(x,y,mouse_x,mouse_y);
     
  10. Waifu_Battle

    Waifu_Battle Member

    Joined:
    Sep 9, 2017
    Posts:
    6
    use image_angle
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice