0
\$\begingroup\$

I have an object the is a perfect circle. The object is moving left, right and jumping with collision detection. What I am trying to do now is rotate the object while it is moving, so it looks like rolling.

This is the code that I have so far:

key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_space);

//1  right, -1 left
var move = key_right - key_left;
hsp = move * walkspd;
vsp = vsp + grv;


if(place_meeting(x, y + 1, oWall)) && (key_jump)
{
    vsp = -7;
}



//horizontal collisions 
if (place_meeting(x + hsp, y, oWall))
{
    while (!place_meeting(x + sign(hsp), y, oWall))
    {
        x = x + sign(hsp);
    }
    hsp = 0;
}
x = x + hsp;



//vertical collisions 
if (place_meeting(x , y + vsp, oWall))
{
    while (!place_meeting(x, y+ sign(vsp), oWall))
    {
        y = y + sign(vsp);
    }
    vsp = 0;
}
\$\endgroup\$
  • \$\begingroup\$ What have you tried? Do you not know how to draw a rotated sprite or are you having trouble determining how far to rotate it? Note: A full rotation is equal to a circumference (roll distance) of pi*D where D is the diameter of your circle \$\endgroup\$ – Peethor Feb 26 '19 at 14:04
  • \$\begingroup\$ I have only tried to to use the inbuilt function image_angle = 1; \$\endgroup\$ – Fred Feb 27 '19 at 2:26
1
\$\begingroup\$

For an exact roll of the circle object based on his displacement use this exact line at the end of your code:

image_angle -= hsp*pi;

The reason of a minus sign is because the roll is clockwise when you go to the right but angles in Game Maker are increasing counter clockwise.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

I think all you need is this in the Step Event:

image_angle += hsp;

image_angle is a variable that decides the rotation position of the sprite. In a number between 0 and 360. You can let it move by adding value to it.

And in case you didn't knew, x += hsp does the same thing as x = x + hsp. But the former makes them more readable.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.