Lying a sprite flat on a polygon

Blitz3D Forums/Blitz3D Beginners Area/Lying a sprite flat on a polygon

earok(Posted 2006) [#1]
Hi all,

Im trying to do a laser sight in my game and the way i've got it going so far is to update the position and orientation of a sprite representing the laser sight every cycle. My code for this section is pretty much as is below.

EntityPick(gun,100)

If PickedEntity() > 0 Then
temprot# = 0
If PickedNZ() > 0 Then temprot# = PickedNZ() * -180
PositionEntity gunsprite, PickedX(), PickedY(), PickedZ()
RotateEntity gunsprite, PickedNY() * 90, (PickedNX() * 90) + temprot#, 0
MoveEntity gunsprite, 0, 0, -0.1
EntityAlpha gunsprite, 1
Else
EntityAlpha gunsprite, 0
EndIf

This way that i've set it up works perfectly for all six sides of a rectangular room, but gets really messy when the gunsight falls on a surface that isn't at 90 degree angles. I would appreciate any help with correcting my code.


Many thanks,


GfK(Posted 2006) [#2]
AlignToVector()

Example in the Castle demo.


earok(Posted 2006) [#3]
Thanks, thats really good.