How to (Fire point location + current perspective)

JohnG

Member
Hi,

Looking for some coding help with retrieving the following through code:

  1. Fire point location of current equipped weapon, in current perspective.
  2. Way to determine when weapon or perspective is changed.
 
1. The First/ThirdPersonShootableWeaponProperties components have the FirePointLocation property which you can access to get the fire point's transform, so you just need to get the appropriate component for currently active item.

2. For determining when the equipped weapon is changed, there is an "OnInventoryEquipItem" event that gets sent by the inventory whenever a new item is equipped, containing the item equipped, so you could simply listen for this event and check which item got equipped. This is described on this page, under "API". You can also find the event under the "Events" section of the character's Inventory component.

For when the perspective changes, assuming the same implementation as in the demo, the CameraController component has a method "TogglePerspective", which is what gets called when the user toggles the perspective with the V key.
 
1. The First/ThirdPersonShootableWeaponProperties components have the FirePointLocation property which you can access to get the fire point's transform, so you just need to get the appropriate component for currently active item.

Using GetComponent? Or is there another way?

2. For determining when the equipped weapon is changed, there is an "OnInventoryEquipItem" event that gets sent by the inventory whenever a new item is equipped, containing the item equipped, so you could simply listen for this event and check which item got equipped. This is described on this page, under "API". You can also find the event under the "Events" section of the character's Inventory component.

perfect.

For when the perspective changes, assuming the same implementation as in the demo, the CameraController component has a method "TogglePerspective", which is what gets called when the user toggles the perspective with the V key.

are you suggesting that I customize the toggle perspective code? If no, then I don’t quite follow.
 
Yes, you can just GetComponent the ShootableWeaponProperties component/s and access FirePointLocation.

As for the camera perspective question, it just depends on how you are planning to have the perspective switching implemented in your game. If you're aiming to just have the same behaviour as in the demo (i.e. a simple toggle between first and third person with a button press), then yes, you could just subclass CameraController and override TogglePerspective, adding any additional functionality in there when the user switches perspectives.
 
Top