# Rotation based on player rotation with offset.

2 replies
Goto Page
1
Goo
User
Offline
Hey! I'm a little... so/so with math.
So I came here after attempting to solve this alone for like an hour.

I have a player (that can rotate of course), that player will cause an event (hook) that will cause projectiles to come out of his left and right "wing" (arms).

Example:

Left and right arrows being where the projectile will launch from (about 16 or 32 pixels from the player) and the circle being the player (with his gun as an arrow (where he's pointing)).

Currently with my random attempts of using random math functions I've made it this far:
Code:
1
2
3
4
local rot = player(p, 'rot')

parse('spawnprojectile ' .. p .. ' 48 ' .. player(p, 'x') - ( _math.tan(rot) * 62 ) .. ' ' .. player(p, 'y') .. ' 320 ' .. rot)
parse('spawnprojectile ' .. p .. ' 48 ' .. player(p, 'x') + ( _math.tan(rot) * 62 ) .. ' ' .. player(p, 'y') .. ' 320 ' .. rot)

(I use
_math.
, but you can use
math.
.)

Of course, that doesn't work otherwise I wouldn't post this
Or would I?
05.06.19 08:44:33 pm
Danilqra
User
Offline
Code:
1
2
3
4
5
6
7
r1 = 20
r2 = -20

rot = player(p, 'rot')

parse(("spawnprojectile %d 48 %d %d 320 %d"):format(p, player(p, "x") + math.cos(math.rad(rot))*r1, player(p, "y") + math.sin(math.rad(rot))*r1, rot))
parse(("spawnprojectile %d 48 %d %d 320 %d"):format(p, player(p, "x") + math.cos(math.rad(rot))*r2, player(p, "y") + math.sin(math.rad(rot))*r2, rot))

Like it ?

r1, r2 - its radius (offset)
Da Ny
05.06.19 09:14:01 pm
Goo
User
Offline
Yes, thanks!
1
﻿