Hat Game Animation

I am creating a game where a ball is placed under a hat and the hats move around and the player guesses what hat the ball is under. I am using transition.to function to move the hats, and that is working, but I want the hats to move in a curve. Is there an equation that I can use to find the curve that can be placed in the transition code? I have researched the Bézier curve but am finding it hard to understand. Thanks

You could try it with a parable.

Parable:

y = (x + a)² * m - b

Estimate the distance between your start and end point, a is half of that value. Now you have to chose wath m should be like. The higher m is, the higher is the wider is the parable. Test around with this a bit, I asume you have set m in relation to a to get the right values. If you use -(x + a)² instead of (x + a)² the parable will flip vertical. The variable b is used to set adjust the highest point of the parable, you have to test aroung with this one too, especially in relation with m.

[LUA]

local normal_distance  = 400

local start_point = 100

local end_point = 400

local step = 0

local b = 0

local math_abs = math.abs

local object = display.newRect(0,0,10,10)

local function parable(x, distance, dir)

   local a = distance * 0.5

   local m = math_abs(distance / normal_distance)

   local y = dir * (x + a)^2 * m - b

   return y

end

local function setPosition()

   local x = step

   local distance = end_point - start_point

   local y = parable(step, distance, 1)

   step = step + 1

  object.x, object.y = x, y

end

Runtime:addEventListener(“enterFrame”, setPosition)

[/LUA]

I did not test this, but it should be a good starting point for you.

You could try it with a parable.

Parable:

y = (x + a)² * m - b

Estimate the distance between your start and end point, a is half of that value. Now you have to chose wath m should be like. The higher m is, the higher is the wider is the parable. Test around with this a bit, I asume you have set m in relation to a to get the right values. If you use -(x + a)² instead of (x + a)² the parable will flip vertical. The variable b is used to set adjust the highest point of the parable, you have to test aroung with this one too, especially in relation with m.

[LUA]

local normal_distance  = 400

local start_point = 100

local end_point = 400

local step = 0

local b = 0

local math_abs = math.abs

local object = display.newRect(0,0,10,10)

local function parable(x, distance, dir)

   local a = distance * 0.5

   local m = math_abs(distance / normal_distance)

   local y = dir * (x + a)^2 * m - b

   return y

end

local function setPosition()

   local x = step

   local distance = end_point - start_point

   local y = parable(step, distance, 1)

   step = step + 1

  object.x, object.y = x, y

end

Runtime:addEventListener(“enterFrame”, setPosition)

[/LUA]

I did not test this, but it should be a good starting point for you.