Forum rules - please read before posting.

Player in vehicle with mesh collider - interaction with interior hotspots

edited October 2022 in Technical Q&A

Hi Chris,

I need a player to ride on a vehicle. For that purpose, I disable the character controller to avoid collision issues (built a custom action and remember component for that), force a sitting animation, reparent the character into the vehicle, disable the movement system, and switch to an in-vehicle camera. That all works well.

However, once I try to interact with the vehicle's interior hotspots, I noticed that this is super hard even with massively oversized hotspots. The reason seems to be that the vehicle has convex mesh colliders. Once I disable them, the interaction works flawlessly. I cannot use the "Ignore Raycast" layer for the vehicle, though, as there are also situations where the player is outside the vehicle where it should obstruct cursor interaction with hotspots behind it.

Please advise!

I am currently on AC 1.75.3.

Thanks
Matt

Comments

  • edited October 2022

    One more observation: there are two mesh colliders on the vehicle, one for the lower part and one for the upper part. The camera for the player's in-vehicle perspective is located in the upper part, while my hotspots are in the lower part. Once I move the camera into the lower part, it works flawlessly, too.

    It's obviously a raycast issue. I could potentially merge both mesh colliders into one to avoid it, but I might get similar issues with hotspots outside of the vehicles mesh collider so I hope there's a better way to work around this.

    Related: when I am using just one mesh collider on the vehicle so that the raycast and hotspot selection from inside the vehicle works, as soon as I click on a hotspot, the player's position changes from the slightly rotated seated position back into an upright position, even though the hotspot's interaction has "Player action: Do nothing" and there's no action list for the interaction yet. Could you advise if there's a way to avoid that?

  • edited October 2022

    It's a compex scenario to visualise - any screenshots you can share to help clarify the exact situation will help.

    It's possible to limit a Hotspot's interactivity to a specific Camera (or multiple, using this script). However, if it's a case of dealing with Raycasts then it's also possible to alter which layer a GameObject is on with a custom script:

    public GameObject[] objectsToAffect;
    
    public void TurnOn ()
    {
        foreach (GameObject objectToAffect in objectsToAffect)
            objectToAffect.layer = LayerMask.NameToLayer (AC.KickStarter.settingsManager.hotspotLayer);
    }
    
    public void TurnOff ()
    {
        foreach (GameObject objectToAffect in objectsToAffect)
            objectToAffect.layer = LayerMask.NameToLayer (AC.KickStarter.settingsManager.deactivatedLayer);
    }
    

    These can be optionally called from ActionLists, with the Object: Send message or Action: Call event Actions.

    as soon as I click on a hotspot, the player's position changes from the slightly rotated seated position back into an upright position, even though the hotspot's interaction has "Player action: Do nothing" and there's no action list for the interaction yet.

    Make sure the Player's Motion control field is set to Manual at the time - this'll be necessary if you're parenting them and looking to override their position while they're in the case. This too can be set at runtime through script with:

    AC.KickStarter.player.motionControl = AC.MotionControl.Manual;
    

    And back again when exiting:

    AC.KickStarter.player.motionControl = AC.MotionControl.Automatic;
    
  • edited October 2022

    Hi Chris,

    Thanks for the prompt response! You're absolutely right, it's easier to visualise. I have prepared a video here:

    I am not yet sure how the layer change would help. The Hotspot layer currently is "Default". Even when I move Hotspots to another layer, I usually want other scene geometry on Default layer to obstruct them. It's just this special in-car scenario that gives me some headache. I am aware of the camera limitations but that wouldn't change the issue in this case.

    EDIT: On a second thought, I assume that you were referring to temporarily moving the car to the "Ignore raycast" layer while being seated. That would help for this issue. But then there's also a traffic system coming into play where other cars will detect collisions using raycast sensors...

    I'll build a custom action for the motion control change and try that. EDIT: Worked!

    Thanks
    Matt

  • edited October 2022

    I added more details in the video description but since it's embedded FYI:

    0s - 17s: I am trying to show that there are two mesh colliders on the car
    17s - 37s: Showing the Hotspot and Camera position - mouse raycast needs to go from mesh collider A through mesh collider B
    38s - 57s: Ingame view of the issue
    57s - 72s: Switch from two mesh colliders to a single Unity-generated one - no issue here

  • I assume that you were referring to temporarily moving the car to the "Ignore raycast" layer while being seated.

    Right. If you need the car to remain on the Default layer for other purposes, however, there are a couple of alternatives.

    One would be to place the Hotspots themselves on a different layer, e.g. CarHotspot, and then alter the Settings Manager's Hotspot layer field to match this when entering the car. This field determines what layer Hotspots are expected to be on - as well as any colliders that may block raycasts.

    To modify a Manager field at runtime, right-click the field's label to get an API reference to it. In the case of Hotspot layer, it's:

    AC.KickStarter.settingsManager.hotspotLayer
    

    The other approach would be to switch your Hotspot detection method field to Custom Script, and then rely on a custom means to detect Hotspots without having other colliders block Raycasts. I can assist with this if this would be necessary, but you may find that the "Screen-space Hotspot detection" package on the Downloads page is workable.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.