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 / firing turret angle help

Author
Message
sovr
14
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 30th Nov 2011 15:46
hello, I am developing an agk app that has a turret in the middle of the map and you are firing at enemies. The thing I am having trouble with is when I rotate the turret how can I make the bullet shoot out in the direction of the turret? I guess I could do a ton of if statement that checks for the angle of the turret, but anyone else have a better way? thank you!

sov the game creator!
bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 30th Nov 2011 15:57
Quote: " I guess I could do a ton of if statement that checks for the angle of the turret, but anyone else have a better way? thank you!"


Look up the angle of the turrent and then align the new object in the same direction, and then thrust it forward.

Check out the following commands:
GetSpriteAngle
SetSpriteAngle


DennisW
15
Years of Service
User Offline
Joined: 15th Jun 2008
Location: Ohio
Posted: 30th Nov 2011 16:23
Hi
I am working on the same type of thing. I have the x and y and the angle what is the line of code that would be to thrust it forward on a stright line.

Dennis

Ham and Eggs Breakfast
The Chicken was involved the Pig was Committed
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 30th Nov 2011 16:55 Edited at: 30th Nov 2011 16:58
i use these functions in my boinkadroid game for my turrets.
The point to command can you simply adjust with -90 or something if it points wrongly.
bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 30th Nov 2011 17:42
This command would apply a force.

SetSpritePhysicsForce

To calculate the correct x and y force, you need to use sin and cos on the angle of your sprite.

Xforce = speed * Cos(angle)
Yforce = speed * Sin(angle)


3d point in space
14
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 30th Nov 2011 18:27 Edited at: 30th Nov 2011 18:30
Well you need to know several things about the turret because it rotates.

First you need to fire from the center point.

This is actually taken out of my game.


Go through yourself at a wall.
DennisW
15
Years of Service
User Offline
Joined: 15th Jun 2008
Location: Ohio
Posted: 30th Nov 2011 20:47
@ Jerico2day
Thanks starting to make sense. Going to need a pot of coffee

Thanks to all

Dennis

Ham and Eggs Breakfast
The Chicken was involved the Pig was Committed
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 30th Nov 2011 21:23
Just to add to J's help, if you are using an aspect rather than a set resolution size you'll need to multiply the Y value by an aspect ratio before using any of the sine rules IE



Login to post a reply

Server time is: 2024-05-04 20:37:56
Your offset time is: 2024-05-04 20:37:56