Discord
Login
Community
DARK THEME

rotation

i need my character to rotate with the axis where he is not in the center

init = function() hero = object x = -50 y = 50 height = 24 width = 24 rotation = 0 end gravity = 1 end

update = function() if hero.y >= -26 then hero.y -= gravity end if hero.y <= -26 then gravity = 0 end if keyboard.LEFT then hero.rotation -= 1 hero.x -= 1 end if keyboard.RIGHT then hero.rotation += 1 hero.x += 1 end gravity += 0.1 end

draw = function() screen.clear("rgb(70,0,0)") screen.setRotation(0) for i = -10 to 10 screen.drawSprite("floor",24i,-50,24,24) end for x = -10 to 10 for y = -74 to -100 screen.drawSprite("floor_two",x24,y*24,24,24) end end screen.setRotation(hero.rotation) screen.drawSprite("ball",hero.x,hero.y,hero.width,hero.height) end

screen.setDrawRotation(rotation). Use screen.setDrawRotation(0) to reset it.

im confused thats what i did in my code

to my understanding, if you don't want it to rotate around the center, you'll have to make the sprite taller in the sprite tab, keeping some empty space below it. that way, when you rotate it, it rotates around a center point close to the feet instead of the core.

the only issue would be with drawing and collision if you use his object width and height, in that you'd have to draw him slightly lower to account for the space as well as having separate height and width for collisions and drawing.

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community