The forum has been set to read-only mode. For community discussion and questions, head over to our Discord: https://discord.taleoftwowastelands.com

Place object behind NPC.

General mod discussion and requests.
Post Reply
garlicred
Posts: 9
Joined: Sat Feb 15, 2014 8:17 pm

Place object behind NPC.

Post by garlicred » Sun Mar 06, 2016 7:57 am

Hello everyone!


I am writing a script which should place object behind NPC on the right side. However now the position is chosen randomly according to HeadingAngle. Can anyone help me make it work properly so object is placed always on the right (left) side of NPC?


Here is the plan:


[url=http://postimage.org/][img]http://s6.postimg.org/7qz7p8241/Instruction.jpg[/img][/url]

 


 


 



let HeadingAngle := PlayerRef.GetAngle Z + PlayerRef.GetHeadingAngle DialogueTargetRef



Print "Player's heading angle is " + $HeadingAngle



set SINus to sin HeadingAngle

set COSinus to cos HeadingAngle





Print "Sin is " + $SINus

Print "Cos is " + $COSinus



    let PosX := 100

    let PosY := 300







Set fRelativePosX To DialogueTargetRef.GetPos X + (PosX * SINus)

Set fRelativePosY To DialogueTargetRef.GetPos Y + (PosY * COSinus)

 




Anacostia Crossing
Posts: 60
Joined: Mon Mar 24, 2014 7:45 am

I believe you shouldn't use

Post by Anacostia Crossing » Sun Mar 06, 2016 12:12 pm

I believe you shouldn't use an offset like (X = 100, Y = 300), but you should use a radial offset (100 * some_angle)


Some_Angle would define the position of the camera, on an imaginary circle around the NPC. Based by where I imagine your camera, I'd say it's something like (GetHeadingAngle - 120).


So:


let HeadingAngle := PlayerRef.GetAngle Z + PlayerRef.GetHeadingAngle DialogueTargetRef



Set MyOffsetAngle to HeadingAngle - 120


set SINus to sin MyOffsetAngle

set COSinus to cos MyOffsetAngle


Set Radius to 100

Set OffsetX to Radius*SINus

Set OffsetY to Radius*COSinus



Set fRelativePosX To DialogueTargetRef.GetPos X + OffsetX

Set fRelativePosY To DialogueTargetRef.GetPos Y + OffsetY


 


Note that you can't use a different Radius between the two axis, or the camera will probably move on an ellipse, around the npc.


 


EDIT: the concept should be correct, but now I'm thinking that GetHeadingAngle is negative in the opposite way. If it's so, then you would require an extra step, first:


Set ExtraStep to Player.GetAngle Z + GetHeadingAngle


And then subtract those 120 degrees. I think. I should simply test it in game and remove every doubt, but I can't right now.



garlicred
Posts: 9
Joined: Sat Feb 15, 2014 8:17 pm

Yes, thanks, Ann, it works!

Post by garlicred » Sun Mar 06, 2016 4:15 pm

Yes, thanks, Ann, it works!



Post Reply