[Dont worry, this is not my game scene]
That angle is the angle for the detection thing
Is there a better and more efficient way to do this?
also what do you call that detection thing?
[follow towards the 12th post, the title of this thread was edited]
if you know who hit you, you can get the world vector wvec = enemy.worldPosition-owner.worldPosition
and then translate it to local space lvec = owner.worldOrientation.inverted()@wvec
you likely want to ignore the Z axis lvec[2] = 0 lvec.normalize()
lastly, you need a hud element that points the axis that the player faces (assume Y).
align the object to your lvec hitdetect.alignAxisToVect(lvec, 1, 1.0) aligns the objects Y to the local hit vector hitdetect.alignAxisToVect([0,0,1], 2, 1.0) aligns to camera to stay flat
i did the * instead of the @ and it kinda works as long as i only move…
but if I turn, the thing goes haywire
update: it goes haywire anyway even if i only move
update 2: it seems to scale up if i bring it too close to the target object
Just a minor change with the angle measurement thing,
step 1>> get enemy position in player local space
step 2>> project the enemy position onto the player’s local x-z plane [basically, enemy.position.y = 0]
step 3>> get angle between the local z axis and the other line from the player’s origin to the projected enemy.
anyone know how to code this?
btw im ok with radians no need to convert it to deg.
Now , i need to do the ‘step 1’ part.
i have to get the coordinates of an object in another object’s local space
how do i do this?
[i edited the title for this]
yes, and you would need a bit more then that, so i created a blend for you let me know if this is what you want.
green = player
red = shooter
orange = indicator
indicator will shows the direction to shooter from the players pos, so if it is a bit off that is correct for the setup we have, parent the indicator to the player and it works flawlessly, now you should be able to either parent it or use it in an overlay scene.
# Hit indicator by cotaks
def test(cont):
own = cont.owner
player = own
hit_locator = own.scene.objects['hit_locator']
shooter = own.scene.objects['shooter']
local_coord = player.worldTransform.inverted() * shooter.worldPosition
angle = player.localOrientation.col[1].angle(local_coord)
ori = player.worldOrientation.to_euler()
ori.z = -angle
pos = player.worldPosition - shooter.worldPosition
if pos.x > 0.0:
ori.z = angle
hit_locator.localOrientation = ori