How to rotate a sprite?

Hello,

I have been trying to rotate a sprite but find it hard to get it right. I simplu just want it to rotate while going from top of screen to bottom of the screen. I am guessing that it is because i don’t understand quaternion and go.set_rotation needs one. Is there an simple example how to rotate an sprite without messing with my downward motion of the sprite, in the sprite i have this script:

function init(self)
	self.speed = 1000

	
end


function update(self, dt)
	local pos = go.get_position()
	pos.y = pos.y - self.speed * dt
	go.set_position(pos)
	go.set_scale(0.8)

end

/Isak

Check the game object documentation and the vmath documentation

3 Likes

Thanks a lot @Mathias_Westerdahl !

Now i have spinning asteroids in my game=) Should i sit down and try to understand quaternions or can i manage without them? Or maybe learn them in a later time?

/Isak

Do not try to understand quaternions, they are not fun…

If you ever want to understand them, here is a little help:

2 Likes

I think i will skip it when, i rather continue with my game the free time i have from kids and work=)

1 Like

I would suggest to learn how to work with them, since they’re part of many engines.

3 Likes

Okey, is there any good tutorials about working with them here at Defold?

1 Like

Really all you need to do is read through the vmath documentation that Mathias linked. There are convenient functions for basically everything you will need to do with quaternions. Also, to add to quaternion rotations together, you multiply them. (kind of like a transformation matrix)

3 Likes

I tried to go through it before but never succeeded but i guess i will go over it once more=)

To learn an api, you usually have to go through several times.
Even if you don’t know what everything does exactly, a little more “sticks” with you each time, and with time you’ll start to connect things together in your head.

3 Likes

I know you are right, but i am tired of it right know, will go though it once again later=)

1 Like