Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Locate my wing positions after sprite rotated

Author
Message
Scotty1973
AGK Backer
12
Years of Service
User Offline
Joined: 2nd Jun 2011
Location: Burton-on-Trent, uk
Posted: 30th Sep 2014 13:20
Hi

Asteroids style game where you have a ship that can rotate and move.

I want to fire laser from wings of the ship. Ship is positioned using center of sprite offsets.

I can calculate the position at 0 degrees from the offset x,y of the ship sprite with no problems.
The question is this:-
How do I calculate these positions after the ship has rotated and moved?
Been trying to use sin and cos but not having much luck with it!
Scary maths ahead me thinks!!

Any help please

Scotty
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 30th Sep 2014 13:41 Edited at: 30th Sep 2014 13:43
the offset is the direction multiplied with distance.

something like this
dx=cos(angle) <- u can use +- angle for left right laser start point
dy=sin(angle)

offset
ox=dx*distance
oy=dy*distance

world coords
wx=shipx+ox
wy=shipy+oy

perhaps exchange sin/cos or the sign before.

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 30th Sep 2014 14:25
Or you could use the built in commands for translating a pixel position on a sprite to a world position (assuming this is 2D?):
Scotty1973
AGK Backer
12
Years of Service
User Offline
Joined: 2nd Jun 2011
Location: Burton-on-Trent, uk
Posted: 1st Oct 2014 07:21
Cheers Markus and Baxslash for your responce.

I have used Markus' way which seemed to work fine for me.

It is a 2D thing baxslash but not too sure how those commands work, mind you it is 5am and i'm supposed to be getting ready for work lol.

Many thanks

Scotty
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 1st Oct 2014 14:06 Edited at: 1st Oct 2014 14:07
...or you could make the laser from a sprite which rotates with the ship.

Saves a load of maths.

Attachments

Login to view attachments
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 1st Oct 2014 14:17 Edited at: 1st Oct 2014 14:18
or modify the laser offset, u can set same pos/rot as ship.
the handle point can be outside image.
(its similar what Marl said.)
SetSpriteOffset( iSpriteIndex, x, y )

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 1st Oct 2014 15:29
I agree with rotating the laser with the ship.

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 1st Oct 2014 16:22
+ ship need gun turret

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265

Login to post a reply

Server time is: 2024-04-24 05:20:20
Your offset time is: 2024-04-24 05:20:20