Hey Chris,
I'm currently using "Turn to face" when the player interacts with a hotspot. However, the player character is holding a flashlight, and when interacting with a hotspot, the flashlight beam still faces either left or right. How can I make the flashlight beam face the hotspot?
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
What does the flashlight consist of, exactly? A sprite or light attached to a child object of the Player? How is it's position/rotation currently set - within the animation?
Yes, it's a 2d light sprite attached to a child object of the Player https://prnt.sc/qBhtsUwyl97i https://prnt.sc/srij-h_jpFq6
It's positioned in front of the flashlight the character is holding.
Presumably, you'd need to change not just the direction, but the position as well - i.e. place the centre of the light over the centre of the Hotspot?
You can use the Events Editor to create a Hotspot: Interact event, which will give you an ActionList that has the Hotspot as a GameObject parameter that can be used to override a Object: Transform Action that places the Light over the Hotspt.
How is it being positioned normally, though? Through animation? If so, the above will likely get ignored as Animation will override it. What you could do here is create a duplicate Light that's used for Hotspots - move it down out of view normally, and then have it show on the Hotspot instead.
No, it's not positioned through animation. This approach seems doable. Could you elaborate on it further, please? Do you mean I need to place a 2D light in the scene and hide it, then make it visible when the player faces the hotspot? If so, how do I disable the player's flashlight when facing the hotspot?
What you could do here is create a duplicate Light that's used for Hotspots - move it down out of view normally, and then have it show on the Hotspot instead.
You could do it like that, but I was suggesting having a 2nd light as part of the Player's prefab - not in the scene. The Light component would be disabled by default. To both, attach AC's Light Switch component.
When the Interaction begins, use a pair of Object: Send message Actions to turn off the normal light, and turn on the duplicate. You'd need to open up the Player's prefab to drag the objects into the Action, but AC will record their Constant ID values so that they can be accessed at runtime.
Additionally, use an Object: Teleport Action to reposition the 2nd light over the Hotspot.
Then, at the end of the Interaction, do the opposite to reverse the effects.
These steps can likely be moved into either events or a custom script to avoid running these Actions manually, but get it working this way with a couple of Hotspots to check the approach first.
I created a second flashlight attached to the player to face the hotspot. Then, I set up a Hotspot: Interact event and used Object: Send Message to turn off the first light and turn on the second. It worked, and the flashlight beam now faces the hotspot when interacting with it. However, there are two issues:
The Hotspot: Interact event can turn on the second flashlight but doesn't automatically revert the effect. I have to manually add actions to each hotspot to switch it back.
Not all hotspots require the player character to face them. With the current approach, the flashlight will always change when interacting with any hotspot.
You can handle this with a script attached to the Player that checks for Hotspots with a specific tag:
Thank you for sharing the script, Chris.
I attached the script to the player's prefab, but I can't drag the flashlight into the normalLight or hotspotLight fields in Unity.
Regarding tags, should I create a new tag named "hotspot_facing" and then assign it to both the flashlights and the hotspot the hotspot that I want the player to face?
Are the flashlights not children of the Player prefab? Be sure to view the Player in Prefab Mode when configuring its Inspector.
All flashlights are children of the Player prefab and opened in the Prefab Mode.
https://prnt.sc/U2vF2yV-UTTz
https://prnt.sc/V5_lP1Jk9kNG
Are you using URP? Replace Light with UnityEngine.Rendering.Universal.Light2D if so.
Yes, I'm using URP. Replacing the light with UnityEngine.Rendering.Universal.Light2D is causing issues and errors. Is there an alternative method that allows me to keep URP?
The change I mentioned was intended to do just that. What were the errors, exactly?
First, the game crashed and then started displaying unlimited red errors, turning all scenes black. In a panic, I deleted the game and pulled the latest repo. That happened on Linux. Today, I tried again on Windows, and while I didn't get those errors, all the scenes are still black.
And this disappears if you remove the script?
Let's see the exact code of the script you're now using.
I removed the script before changing the render pipeline, so it's clear the issue isn't related to the script.