LoginLogin

Rotating sprite to stick values?

Root / Programming Questions / [.]

NoxusCreated:
Basically I'm having a sprite move using values I got from STICK. Thing is, I need the sprite to point towards whatever direction the stick is pointing in. For reference heres my code so far: Spset 1,100,100,-64 @gameloop Stick out POSINFOX,POSINFOY POSX=POSX+POSINFOX*2:POSY=POSY-POSINFOY*2 Spofs 1,POSX,POSY VSYNC 1 GOTO @gameloop

I put this code in my 3DS and nothing showed up...

I put this code in my 3DS and nothing showed up...
I didn't post the very first part, I just posted the meat of what I have. I wasn't expecting anyone to try it out physically otherwise I would've uploaded it, I was just trying to see if someone could help me with the logic invovled. My bad!

Oops lol then from my small experience with sprites, it looks like it would work. But what do I know? I don't use sprites lol

You want to rotate the sprite so it's pointing in the direction/angle the stick is pointed? Try this:
SPROT 1,DEG(ATAN(POSINFOX,POSINFOY)
SPROT takes an angle (in degrees) and sets the rotation angle of the given sprite (in this case 1). ATAN(), when given 2 parameters, will determine the angle of the coordinate relative to the origin (in radians). We use DEG() to convert the result of ATAN() to a degree value.

That's cool. I would have never thought of that

I was working on this and had figured the trigonometry part with rotation, but there's a problem with rotation since the angle of rotation is based on the upper left corner, not the center. The problem causes the sprite to jump around when you alternate between two different directions (as in, pressing up, down, up, down will cause the sprite to jump left and right). I couldn't figure out how to fix that.

You want to rotate the sprite so it's pointing in the direction/angle the stick is pointed? Try this: SPROT 1,DEG(ATAN(POSINFOX,POSINFOY)) SPROT takes an angle (in degrees) and sets the rotation angle of the given sprite (in this case 1). ATAN(), when given 2 parameters, will determine the angle of the coordinate relative to the origin (in radians). We use DEG() to convert the result of ATAN() to a degree value.
This is exactly the kind of idea I had in mind, you just worded it for me correctly. Thanks this helps a ton! I figured it was something close to that.
I was working on this and had figured the trigonometry part with rotation, but there's a problem with rotation since the angle of rotation is based on the upper left corner, not the center. The problem causes the sprite to jump around when you alternate between two different directions (as in, pressing up, down, up, down will cause the sprite to jump left and right). I couldn't figure out how to fix that.
The angle of rotation with the sprite itself? I think I can change that with SPHOME, if not, I'll have a look at in. Thanks for the input!

Oh wait, the guy above me already posted about SPHOME. Oh well.

Okay so I used the trig as mentioned earlier, but the problem is my triangle sprite rotates facing INWARDS to where I'm moving it, aka if I move the circle pad in a circle the triangle faces inwards/the opposite direction I want it to. This doesn't seem to be a problem with SPHOME, because if I use that it just changes where the rotation starts, and not the orientation itself. Make any sense?

Try taking the negative of the y-offset. The stick returns negative when pushing down, but screen coordinates are positive when traveling down. If this isn't what you're asking about, sorry. I'm a bit iffy on the wording of your question.

It could be that the sprite is upside down.

Alright so I figured out the rotating problem, it was an issue with the sprite itself. Thanks everyone!