I am trying to make a FPS for android and have controls setup like this
I am using Touch delta for looking and Left stick (which I made using on screen stick script) for moving. Problem is that whenever I move the stick the touch delta is also registered and camera starts rotating.
So if I could restrict the touch delta to say right side of the screen it would work out. But I cant wrap my head around how to do it.
Or any other way through with which I can perform movement with stick and look with the empty space around the stick.
EDIT:
So this is what ended up doing
I made a custom onscreen control where I calculate pointer local position and attached it to a empty UI which is same size as of screen and made sure all other UI are on top of it. And used virtual mouse delta for control path.
Don’t know whether this is the best way to do this but it works.
Maybe it would be better to use custom composite binding with touchscreen.
Also there was a problem when I was setting control path to right stick. It was auto clamping(between -1 to 1) the values which the script was sending.
Unfortunately, this is indeed down to workarounds ATM. “Routed input” on actions, i.e. the ability for input to actually be consumed by one action and prevent input on another action, is high up on the list for after 1.0. When this is in, input that is consumed by the UI input module will prevent input on gameplay actions (except if let through).
So is there a work around this case…
1 Like
It’s been four years and that “high up in the priority list” is yet to come
Here’s my OnScreenControl solution if you control your Look action with pointer/mouse/touch delta
- Bind the Look action to Mouse Delta instead of Touchscreen or Pointer Delta
- Add this component to a raycast target in your canvas that represents the area you want to control the look input
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.OnScreen;
/// <summary>
/// Send pointer delta to the <see cref="OnScreenControl.controlPath"/> when dragging inside the area of the <see cref="OnScreenPointer"/>.
/// </summary>
public class OnScreenPointer : OnScreenControl, IPointerDownHandler, IPointerUpHandler, IDragHandler
{
[InputControl(layout = "Vector2")]
[SerializeField]
private string m_ControlPath;
protected override string controlPathInternal
{
get => m_ControlPath;
set => m_ControlPath = value;
}
public void OnDrag(PointerEventData eventData)
{
SendValueToControl(eventData.delta);
}
public void OnPointerDown(PointerEventData eventData)
{
}
public void OnPointerUp(PointerEventData eventData)
{
}
}
- Set the Control Path in the inspector to Mouse Delta
Using a mouse will bypass this on-screen control but that should be fine if you use the usual way of locking and hiding the cursor.