#Isometric controls

1 messages · Page 1 of 1 (latest)

ember elm
#

Hello, i'm making an isometric game :)
On keyboard everything work fine, like when pressing W the player will move top right.
Problem is that, when i connect a controller, putting joystick up will move player top right. But that feel weird and i want player to move exactly like joystick orientation.
So, i want to know if there is a way to correct that easily or if i have to modify the code to check for keyboard or controller.

gilded loom
#

You'd have to share your code and how you set up your input handling

#

there's no magic here that is making that work as expected

#

it's likely code you wrote doing it

ember elm
gilded loom
#

not this one

ember elm
#

Basicly player move forward using keyboard but when using the xbox controller, the control is different cause my camera is isometric and isn't behind player

gilded loom
#

Or sorry

ember elm
gilded loom
#

rather the StarterAssetsInputs.cs script

#

ok there's nothing really in here - so it will then be coming from how the input actions asset is configured

ember elm
#

the problem is from the fact that camera is rotated compared to player

gilded loom
#

Your explanation doesn't make sense to me.

ember elm
gilded loom
#

but you actually want it to behave differently?

ember elm
#

i mean when you play isometric game on controller shouldn't placing joystick up makes character go up ?

gilded loom
#

IDK, that's up to you as the game designer

#

if that's what you want then yes you'll need to add some special handling for it

gilded loom
#

I would make a different input action for the joystick, unbind it from the nroaml move action, and add a separate handling path for that that rotates the vector 45 degrees before feeding into the movement script

ember elm
#

i guess i just need to add roation based on camera position cause i'm not even sure it's 45 degrees. bruh

gilded loom
#

Either that or you need to write a custom processor that rotates the vector and use that for your joystick binding

ember elm
#

great, i'll do that :O

daring cosmos
#
    {
        Vector3 dir = transform.forward * inputManager.verticalInput;
        dir += transform.right * inputManager.horizontalInput;

        dir.y = 0;
        dir.Normalize();

        return dir;
    }
``` this is how i handle my isometric movement
#

and rotation with

    PlayerControls playerControls;
    InputManager inputManager;
    PlayerLocomotion locomotion;
    public Camera cam;

    [Header("Rotation Settings")]
    public float smoothTime = 0.07f;
    public float rotationSpeed = 400f;

    private Vector3 currentEuler;
    private Vector3 velocity;

    void OnEnable()
    {
        if (playerControls == null)
            playerControls = new PlayerControls();
        inputManager = GetComponent<InputManager>();
        locomotion = GetComponent<PlayerLocomotion>();

        playerControls.Enable();
    }

    void OnDisable() => playerControls.Disable();

    void Start()
    {
        if (cam == null)
            cam = Camera.main;

        currentEuler = transform.eulerAngles;
    }
#
    {
        Vector2 screenPos = playerControls.PlayerMovement.Look.ReadValue<Vector2>();

        if (screenPos.sqrMagnitude < 0.01f)
            return;
        
        // Project screen → world at player's height (no raycasting)
        Vector3 mouseWorld = ProjectToPlayerHeight(screenPos);

        Vector3 dir = mouseWorld - transform.position;
        dir.y = 0f;

        if (dir.sqrMagnitude < 0.0001f)
            return;

        float angle = Mathf.Atan2(dir.x, dir.z) * Mathf.Rad2Deg;

        float newY = Mathf.SmoothDampAngle(
            currentEuler.y,
            angle,
            ref velocity.y,
            smoothTime,
            rotationSpeed
        );

        currentEuler.y = newY;
        transform.eulerAngles = currentEuler;
    }

    // ------------------------------------------------------------
    // :earth_americas: World Projection (NO RAYCASTS)
    // This projects the mouse onto the player's height
    // using pure camera projection math.
    // ------------------------------------------------------------
    Vector3 ProjectToPlayerHeight(Vector2 screenPos)
    {
        // Convert screen position to a 3D point on the camera plane
        Vector3 near = new Vector3(screenPos.x, screenPos.y, cam.nearClipPlane);
        Vector3 far = new Vector3(screenPos.x, screenPos.y, cam.farClipPlane);

        Vector3 p0 = cam.ScreenToWorldPoint(near);
        Vector3 p1 = cam.ScreenToWorldPoint(far);

        // Direction of projection
        Vector3 v = p1 - p0;

        // Solve for intersection with horizontal plane at player's Y
        float t = (transform.position.y - p0.y) / v.y;

        return p0 + v * t;
    }

NOTE :: these are very basic and are a base package i made to start working on isometric games, the movement needs tweaked and isnt perfect this is just to show the logic