Using "image_angle" for a loop cage pendant effect

K

klanes

Guest
Hi guys! i have a new noob question...

I have a jail sprite hanging on a rope. I want to code a pendulum movement loop. I've tried a thousand ways using "image_angle", but I'm able to do it :\ (i want a coder brain in my head! XD)



It would also be great if the movement were smooth at the ends, like a real pendulum movement.

Here is the last version of my code (I know is a wrong code, only is the last attempt)

Create:
image_angle = 10;
rotacion = image_angle;

Step:
if rotacion <= 10;
{
image_angle -= 0.05;
}
if rotacion >= 350;
{
image_angle += 0.05;
}

----------

Many thanks for your help!!!
 
K

klanes

Guest
Use a sine wave.
Code:
image_angle=default_angle+range*sin(xx)
xx+=.1
Thanks for your reply... i'm really newie with the code and GM... This code must be in a "Step" event, inside the object jail? With this code the jail don't move:

Step evento:
image_angle = 0+10*sin(xx)
xx+=.1

Sorry, I feel really clumsy!
 
K

klanes

Guest
Hm, odd. Would you mind posting all the relevant code in the cage object?
Sure!
Here is my "obj_jaula" settings:

And here is the code into "step" event:

image_angle = 0 + 10*sin(xx)
xx += 0.1

When the game start the cage appear stopped :\
 

Roderick

Member
I wonder if 10*sin(xx) is making it return to the same position every step. Could you change the 10 to some other number and see what happens please?

It's also possible that the movement is too small to notice. Try a bigger number.
 
K

klanes

Guest
I wonder if 10*sin(xx) is making it return to the same position every step. Could you change the 10 to some other number and see what happens please?

It's also possible that the movement is too small to notice. Try a bigger number.
Don't works... i have tried different numbers and the cage appear stopped :\
 

Roderick

Member
Don't works... i have tried different numbers and the cage appear stopped :\
I don't know what to tell you. I just made a new project with nothing but a single object with that code in it, and it worked perfectly. Something somewhere else must be affecting its image_angle.
 
K

klanes

Guest
I don't know what to tell you. I just made a new project with nothing but a single object with that code in it, and it worked perfectly. Something somewhere else must be affecting its image_angle.
Oh!! i'm an idiot XD I must add a "Create" event to declare de "xx" var like "0", then works ok!!!

THANKS A LOT! and sorry for my noob questions! :)
 

sp202

Member
GM should have given you an error if xx hadn't been declared, have you turned off errors by any chance?
 
K

klanes

Guest
I was testing the game for HTML5 and no, GM did not give me any error. It was when i tried run the game for windows mode that gave me the errors.
 

sp202

Member
Ah, that makes sense. It's probably safer to stick to testing on Windows and periodically testing on HTML5.
 
Top