Fangames > Programming Questions

Make cherry move in Archimedian spiral with constant speed?

<< < (3/3)

kilgour22:
If you want your spiral to go inwards, than you need your radius to be constantly reducing. This is achievable by multiplying with a spiral factor of 0 < spiral_factor < 1. Choosing a negative value will simply reverse the direction, but the radius is still increasing due to the factor being greater than 1.

zaphod77:
That does not do what you think it does.

That just makes a wider outward spiral. one wayyyyy too big to even try to put.

here's what I"m doing

current_distance=point_distance(x,y,originx,originy);
reverse=1;
if (spiral_direction==1)
{
reverse=-1;
}
direction=spiral_factor*current_distance*reverse;

No amout of tweaking prevents it from either wiggling around like crazy if the factor is too high for the speed, or making it's way to and the following an outward spiral.

zaphod77:

--- Quote from: infern0man1 on January 20, 2016, 05:34:01 PM ---I'm not sure what you mean by that then. With what I did, you create a cherry with a radius of, say, 800 pixels, from a central point that you define, meaning the cherry is 800 pixels away from it's central point; the cherry will always move into where you set it's centerX and centerY ...

--- End quote ---

You have the distance from center increasing or decreasing at a constant rate. that means the speed gets faster as it goes farther form the center, and slows down as it gets closer to the center.

That's exactly the opposite of what i want. i want the speed builtin variable of the object to remain constant, and only it's direction to be changed. this means as it goes farther from center, the radius will increase slower, because it will take longer to loop around each time.

The ratio method does this fine, but only for outward spirals.

L4Vo5:
i THINK this is what you want. Tough this doesn't use the direction so if you truly need that i think there's a simple way to calculate it.
Also make sure to not start the instance at centerx and centery or it will be destroyed (making it 0.00001 pixels away should do)

create event:
spd = 2 //set to negative to move clockwise
move = 10 //ammount of pixels moved per revolution, negative value means that it moves inwards
len= distance_to_point(centerx,centery)
dir = point_direction(centerx,centery,x,y)

step event :
if len <= 0 instance_destroy()
chng = 360*(spd/(len*pi))
dir += chng
len += move/(360/chng)
x = centerx+lengthdir_x(len,dir)
y = centery+lengthdir_y(len,dir)

L4Vo5:
If you want direction, change

x = centerx+lengthdir_x(len,dir)
y = centery+lengthdir_y(len,dir)

to

direction = point_direction(x,y,centerx+lengthdir_x(len,dir),centery+lengthdir_y(len,dir))

And make sure to change spd to speed anywhere that it's used

Navigation

[0] Message Index

[*] Previous page

Go to full version