Advertisement

Rotating Sprite Around A Point Without Messing Its Drawing Point

Started by November 19, 2019 01:34 AM
11 comments, last by lifesuxtr 5 years, 2 months ago
19 hours ago, JohnnyCode said:

why do you compete a single 3x2 matrix multiplication of a 2d vector with normalization and funcy stuff OP does?

Uhm, excuse me, but what? I was talking about vector multiplication by a scalar value. The OP's question was: provided T,P,A known, how to get C? I answered that question and gave a few pointers on how to rotate a bitmap arrow. Neither of those require matrix operations. That was all. I've answered how I would do it with the given configuration, now the rest is up to the OP.

Cheers,
bzt

@Zakwayda

You are right. I have decided to work on rotation first.I fixed position of arrow to center of circular body and i am trying to face arrow towards aiming point.

(shooter is central body)

var xDownPoint = shooter.body.position.x-powerIndicator.width/2  
var yDownPoint = shooter.body.position.y  
powerIndicator.setPosition(xDownPoint,yDownPoint)  
var degrees = (Math.atan2((aimingPoint.x - xDownPoint).toDouble(), -(aimingPoint.y - yDownPoint).toDouble()) * 180.0 / Math.PI - 180.0f).toFloat()     powerIndicator.setOrigin(xDownPoint,yDownPoint) 
powerIndicator.rotation = degrees

This is the result:

https://im4.ezgif.com/tmp/ezgif-4-21ee1394147e.gif

As you see starting position of arrow is messed up but i guess rotated correctly.

This topic is closed to new replies.

Advertisement