Hmm, I have a platformer/shooter, in which the player can shoot in 360 directions (about -doesnt have to be exact). Im trying to figure out a way to keep the scope (object) a certain distance from the player, yet have the mouse (hidden) rotate the scope so the gun rotates and shoots in the direction of the Scope.
Its not enough,I need more
Not enough to satisify
I said I dont want it, I just need it.
To believe, to feel, to know I'm alive.
Knuckle deep beneath the borderlines.
This may hurt a little but its something you'll get used to.
Relax. Slip Away...
get distance using:
Square root ((X2-X1)² + (Y2-Y1)²)
In this case, (X2,Y2) would be the scope co-ordinates, and (X1,Y1) would be the player co-ordinates.
Check to see if that is greater than a certain value, and if it is, use a fastloop to reduce the x and y distances.
Individual distances are just a simple |x2-x1|, |y2-y1| (|| indicates taking positive value).
That's a simple way a more efficient, albeit complex way would be to use cos and sin.
angle: atan((Y2-Y1/X2-X1)) in degrees
i.e X distance = dCosθ
Y distance = dSinθ
where d = max radius
i actually found a really easier way for the distance was just to make the scope however any pixels i want the distance to be - 120 pixels, and have the hotspot in the left center of the frame - so that in each direction rotated, and having the hotspot always on the player, the scope never leaves the player spot -but it's not good though.
Hmm, I want to be able to control the scope with the mouse rather than just rotate it - hmm ill keep hacking away
Its not enough,I need more
Not enough to satisify
I said I dont want it, I just need it.
To believe, to feel, to know I'm alive.
Knuckle deep beneath the borderlines.
This may hurt a little but its something you'll get used to.
Relax. Slip Away...
Always:
-Frame: Set horizontal scrolling to X(Player)+X(Targeting Reticule)/Zoom Coefficient (a value)
-Frame: Set vertical scrolling to Y(Player)+Y(Targeting Reticule)/Zoom Coefficient (a value)
-Player Sprite: Always look in direction of Targeting Reticule
A Zoom Coefficient of 2 prevents the player from ever leaving the screen and is good for every weapon. If you want to add a sniper rifle or scoped weapon, you can increase the zoom coefficient, though the player sprite will sometimes leave the screen (which is a bit accurate to simulate tunnel vision).
If wishes were fishes then we'd all smell like ladies' underwear.