Be the first to post for '22_MA_RPG'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.

Hey @Rick_Davidson what’s Justin Timberlake’s house about? Why is he in your game?

1 Like

@midasPrimaris Nice, someone noticed! :slight_smile:

The honest answer is that I was naming my prefabs and this house was a timber house. I looked at “timber house” and thought I could give it a more nifty name. And secondary answer is that I thought it was a bit odd and quirky and felt that matched our game.

2 Likes

@Rick_Davidson You should have Justin Timberlake’s house be a wood house on the side of a body of water :wink:

1 Like

My implementation keeps input handling out of PlayerMovement which is passed button driven events rather than ‘mouse over’ events. I also came up with a way to check if the cursor is over a NavMesh.

In CursorAffordance I have the following events:

    public delegate void _OnTerrainClick(Vector3 location);
    public event _OnTerrainClick  OnTerrainClick;

    public delegate void _OnEnemyClick(Enemy enemy); //TODO implement
    public event _OnEnemyClick  OnEnemyClick;

This is my version of RayCastForWalkable. The isOnNavMesh function checks to see if the cursor is over the navmesh. I also check to make sure that OnTerrainClick has at least one subscriber before calling to prevent run-time exceptions. I was really surprised that C# doesn’t protect against this.

    private bool RayCastForWalkable(Ray ray) {
    RaycastHit raycastHit;
    LayerMask potentiallyWalkableLayer = 1 << POTENTIALLYWALKABLELAYERNUMBER;
    bool potentiallyWalkableHit = Physics.Raycast(ray, out raycastHit, maxRaycastDepth, potentiallyWalkableLayer);
    if (potentiallyWalkableHit && isOnNavMesh(raycastHit.point)) {
        Cursor.SetCursor(walkableCursor, hotSpot, CursorMode.Auto);
        if (Input.GetMouseButtonDown(0) && (OnTerrainClick != null)) OnTerrainClick(raycastHit.point);
        return true;
    }
    return false;
}

 public static bool isOnNavMesh(Vector3 point) {
    const float MAX_DISTANCE_FROM_POINT = 0.2f;  //Adjusted through testing
    NavMeshHit navMeshHit; //Required for Sampleposition call
    return  NavMesh.SamplePosition(point, out navMeshHit, MAX_DISTANCE_FROM_POINT, NavMesh.AllAreas);
}
1 Like

It’s probably a simple solution but I’m struggling to figure it out right now. I’ve edited my CameraRaycaster script to include:

    [SerializeField] int[] layerPriorities = null;
    [SerializeField] Texture2D walkCursor = null;
    [SerializeField] Vector2 cursorHotspot = new Vector2(0, 0);

I’ve saved it, and even to the point of the video where my character will move again (so I know its been updating), but the camera raycaster in the inspector will not update to allow me to re-add the walk icon. The Cursor Affordance has updated and removed the walk cursor, but nothing seems to get it to show up under the Camera Raycaster. Can anyone help figure out what I’ve missed or howI can get Unity to update and see it?

To answer my own question in case anyone else has the same problem, apparentlyI didn’t properly removed the raycastereditor script, which then fixed it.

Privacy & Terms