LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

turret example

Root / Programming Questions / [.]

RetroMusicCreated:
Hello everyone, I've been working on mml since petit computer. I've never really tried to make a game but rather focus on music. Could someone please make an example on how to make a turret shoot depending if the target is inside a radius? Also would trigonometry be involved?

There's plenty of ways to do this, but I think the only trigonometry involved would be to decide the angle that the turret should face. Sorry, I don't have access to SmileBASIC for the foreseeable future, so I can't make an example. Off-topic, how good are you with MML? Would you be interested in composing for someone else's game? I'm great at programming but can't make any sort of music (or graphics, for that matter).

I think you will also need the x and y axis of the thing you want the turret to shoot and have it declare if they come close to the turret then it activates the shots. Although I could be wrong

I think you will also need the x and y axis of the thing you want the turret to shoot and have it declare if they come close to the turret then it activates the shots. Although I could be wrong
I'll try that

There's plenty of ways to do this, but I think the only trigonometry involved would be to decide the angle that the turret should face. Sorry, I don't have access to SmileBASIC for the foreseeable future, so I can't make an example. Off-topic, how good are you with MML? Would you be interested in composing for someone else's game? I'm great at programming but can't make any sort of music (or graphics, for that matter).
Ah its OK, and I'll see what I can manage to do with angles As for mml I think I'm OK, I haven't really got any of my works published before and I don't really rely on myself to judge what I can make.

This is actually all trig. You use the distance formula with the x and y of your player, and your turret to compute the distance: D^2=(Px-Tx)^2+(Py-Ty)^2 And the angle will be using tangent: The line between your turret and (Px,0) and the line between the turret and (0,PY) form two sides of a triangle (opposite and adjacent SOHCAHTOA) Atan(Px-Tx, Py-Ty) Edit: fighting the tablet while I think. I had it right the first time

This should get you started: QKAE54G3. This is an example of detecting if the player has entered the "kill zone". This came from part of a game I was working and there might be a better way of doing this.

Interesting

I'm experimenting with all sorts of equations I found online, your program seems really simple then the rest

This should get you started: QKAE54G3. This is an example of detecting if the player has entered the "kill zone". This came from part of a game I was working and there might be a better way of doing this.
Thanks

This is actually all trig. You use the distance formula with the x and y of your player, and your turret to compute the distance: D^2=(Px-Tx)^2+(Py-Ty)^2 And the angle will be using tangent: The line between your turret and (Px,0) and the line between the turret and (0,PY) form two sides of a triangle (opposite and adjacent SOHCAHTOA) Atan(Px-Tx, Py-Ty) Edit: fighting the tablet while I think. I had it right the first time
I input the formula and get an error

This should get you started: QKAE54G3. This is an example of detecting if the player has entered the "kill zone". This came from part of a game I was working and there might be a better way of doing this.
Mine if I take your code and do some modifications? I need this kind of mechanic's for a game I'm making and if you want I'll add you in the credits.

This should get you started: QKAE54G3. This is an example of detecting if the player has entered the "kill zone". This came from part of a game I was working and there might be a better way of doing this.
Mine if I take your code and do some modifications? I need this kind of mechanic's for a game I'm making and if you want I'll add you in the credits.
Sure. :)

This is actually all trig. You use the distance formula with the x and y of your player, and your turret to compute the distance: D^2=(Px-Tx)^2+(Py-Ty)^2 And the angle will be using tangent: The line between your turret and (Px,0) and the line between the turret and (0,PY) form two sides of a triangle (opposite and adjacent SOHCAHTOA) Atan(Px-Tx, Py-Ty) Edit: fighting the tablet while I think. I had it right the first time
I input the formula and get an error
That's math not code :) Just being your friendly neighborhood pedant. The code might be Distance:
VAR D = SQR(POW(PX-TX,2),POW(PY-TY,2))
Angle
VAR ANG=ATAN(PX-TX,PY-TY)

This should get you started: QKAE54G3. This is an example of detecting if the player has entered the "kill zone". This came from part of a game I was working and there might be a better way of doing this.
Mine if I take your code and do some modifications? I need this kind of mechanic's for a game I'm making and if you want I'll add you in the credits.
Sure. :)
Thank you !!!

This is actually all trig. You use the distance formula with the x and y of your player, and your turret to compute the distance: D^2=(Px-Tx)^2+(Py-Ty)^2 And the angle will be using tangent: The line between your turret and (Px,0) and the line between the turret and (0,PY) form two sides of a triangle (opposite and adjacent SOHCAHTOA) Atan(Px-Tx, Py-Ty) Edit: fighting the tablet while I think. I had it right the first time
I input the formula and get an error
That's math not code :) Just being your friendly neighborhood pedant. The code might be Distance:
VAR D = SQR(POW(PX-TX,2),POW(PY-TY,2))
Angle
VAR ANG=ATAN(PX-TX,PY-TY)
Oh lol OK. Thanks