The Daily Click ::. Forums ::. Klik Coding Help ::. Setting a Direction
 

Post Reply  Post Oekaki 
 

Posted By Message

Paul_James



Registered
  02/07/2002
Points
  1320
25th March, 2007 at 16:46:30 -

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...

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
25th March, 2007 at 16:52:13 -

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

Image Edited by the Author.

 
My signature is never too big!!!

Paul_James



Registered
  02/07/2002
Points
  1320
25th March, 2007 at 17:40:17 -

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...

Bo Fu



Registered
  02/04/2004
Points
  413

VIP Member
25th March, 2007 at 18:29:25 -

What I do for aiming:

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.
   

Post Reply



 



Advertisement

Worth A Click