Rotate point

Hi, whenever I try to do rotate(CurrentTouch.y / 2) it works fine, but when I do rotate(CurrentTouch.y, x, y)
it doesn’t work. Any ideas?

function draw()



sprite("Custom", WIDTH / 2, HEIGHT /2, 44, 128)


translate(WIDTH/2, HEIGHT/2)

rotate(CurrentTouch.y / 2, WIDTH/2, HEIGHT/2)

sprite("Custom2", 0,0, 8, 36)


I believe that rotate() rotates around 0,0 and so to get it to rotate around a point you translate, which it appears you’ve done. I don’t understand why you need the x,y in rotate?

Because rotate() can also have a custom place to rotate around, and Since “Custom2” is an arm, I want the shoulder to be the rotate point.

@Prynok, as far as I can tell if you use a rotate point you must include a z value, look at the documentation.

Tried, it still doesn’t like me

@Prynok .It’s the same when you’re doing an animation.
Why?: in your example when translate then sprite, you are giving the position where the image will appear, then when u rotate , you are giving only the value of z, when you rotate an image, you cant not pass the values ??of x, y, these will move when you touch the screen giving the target in the same sprite

sprite("Custom2", WIDTH/2-300,HEIGHT/2-200, 8, 36)

function setup()
      mensaje = {x=WIDTH/2,y=HEIGHT/2+700,z =100}

function draw()
      tween(1,mensaje,{x = WIDTH/2,y = HEIGHT/2+150, z = 100},
     {easing = tween.easing.backIn,
     loop = tween.loop.once})
    sprite("Cargo Bot:Codea Logo")


@Prynok There is no easy way to do what you want. rotate() doesn’t take three variables, it only takes one or four. If you use one, it’s degrees for rotation in 2D. If you use four, the first variable is degrees, and the next three are x, y, and z. The last three are either 0 or 1. Four is used for 3D rotation.

Couldnt you just translate to the correct point and then rotate around that?

@SkyTheCoder: “The last three are either 0 or 1.” If you mean that literally then you’re wrong. The last three inputs to the rotate function specify the axis to rotate about so can be anything, although 0,0,0 is a silly choice (not actually sure what it will do with that input).

rotate(angle,x,y,z) rotates by angle about the axis (x,y,z). There’s no function for “rotate about a point”. What you have to do is what @JakAttak says: translate so that the point you want to rotate about is at the origin, do the rotation, and then translate back again.

function draw()
    sprite("Cargo Bot:Codea Logo",WIDTH/2,300)

@Andrew_Stacey Odd, whenever I used the x, y, z in rotate other than 0 or 1, I think either nothing happened or Codea crashed, not sure which.

@SkyTheCoder It’s a 3D thing so if you don’t have the matrices set up correctly then it’s easy to rotate your stuff off the screen (remember that things get clipped if they are too close or too far away as well).