Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module 3 Assignment #74

Closed
8 tasks done
jaakop opened this issue Oct 24, 2023 · 5 comments
Closed
8 tasks done

Module 3 Assignment #74

jaakop opened this issue Oct 24, 2023 · 5 comments
Assignees
Milestone

Comments

@jaakop
Copy link
Contributor

jaakop commented Oct 24, 2023

Assignment
Emil

  • Completed tasks
  • In-progress tasks

Aleksandar

  • Completed tasks
  • In-progress tasks

Jaakko

  • Completed tasks
  • In-progress tasks

Leevi

  • Completed tasks
  • In-progress tasks
@jaakop jaakop added this to the Module 3 milestone Oct 24, 2023
@jaakop
Copy link
Contributor Author

jaakop commented Oct 29, 2023

Completed

Fish collision avoidance

In order to avoid collision with the environment the fish does checks to ensure that the next waypoint is available (no collision with environment between it and current position). To do this the fish casts a ray from its position to the target. If the ray collides with the environment colliders it moves the point around it self and tries again. This is done until a suitable point is found.

protected Vector3 AvoidCollissionsWithEnv(Vector3 point)
{
    // 1 << 3 -> Check for collissions only on layermask no. 3
    while (Raycast(point, 1 << 3))
    {
	    point = RotatePointAroundFish(point, collissionAvoidanceTurnRate);
    }
    return point;
}

protected bool Raycast(Vector3 point, int layerMask)
{
    var pos = transform.position;
    var dir = point - pos;
    return Physics.Raycast(pos, dir, dir.magnitude, layerMask);
}
private Vector3 RotatePointAroundFish(Vector3 point, float amount)
{
    var pos = transform.position;
    return pos + Quaternion.AngleAxis(amount, Vector3.up) * (point - pos);
}

This implementation itself may cause the fish to create an infinite loop where no point is ever found. Assuming that the the point, where the fish is currently, is a valid point, we can move the point closer to the fish each iteration. This creates a spiral pattern that gets closer and closer to the fish and thus eventually finds a suitable position.
Pasted image 20231029174630
(Yellow = initial point, Red = invalid point, Green = valid point)

protected Vector3 AvoidCollissionsWithEnv(Vector3 point)
{
    var distanceModifier = 1f;
    // 1 << 3 -> Check for collissions only on layermask no. 3
    while (Raycast(point, 1 << 3))
    {
        point = RotatePointAroundFish(point, collissionAvoidanceTurnRate, distanceModifier);
        distanceModifier *= 0.9f;
    }
    return point;
}

private Vector3 RotatePointAroundFish(Vector3 point, float amount, float distanceModifier)
{
    var pos = transform.position;
    return pos + Quaternion.AngleAxis(amount, Vector3.up) * (point - pos) * distanceModifier;
}

Code to make the point close in on the fish.

Pasted image 20231029181017

Fish spawning rework

Partially as a scriptable objects demo I reworked the fish spawning to utilize scriptable objects.

[CreateAssetMenu(fileName = "Data", menuName = "ScriptableObjects/FishSpawnObject")]
public class FishSpawnObject : ScriptableObject
{
    public GameObject prefab;
    [Tooltip("Amount of fish to spawn")]
    public int amount;
    [Range(0, 10), Tooltip("Weight of this type when it is selected randomly")]
    public int weight;
    [Tooltip("Limit the fish to only one on the screen at a time")]
    public bool Limit;
}

Also to support spawning groups of fish instead of only random fish. This makes the boid fish feel better as it ensures that if they are spawned, a group of the will be spawned.
Pasted image 20231029182449

Home

Pasted image 20231029182627
I started creating home scene, where the player goals are presented. The goal of the player is to payback a loan from the loanshark. I created the new scene, scene management and timer to the fishing scene to return the player to the home scene. I've also created a base for the loan payback feature that on top of which can the paying, winning and losing mechanics be build on.
Pasted image 20231003200755

In progress

For the future I plan to only help and guide the other to get them coding as well.

@Laffey-chan
Copy link
Contributor

Completed

Advancing next day

This was simple to implement because it was just using the session manager that has function to advance next day it was just adding the day counter also to this when advancing to next day
image

Adding the money from fishes

This i added to the player controlscript that has information about the fish that is in the hook so i could do scriptable object and just getting the reference from the fishobject and the the fish value. So the money is added to the player when the minigame end, and the recast also dosen't call the money function so it wouldent give the reference error for the script

image
image
image

Money and loan text for menu and in game

There was money already but i needed to add loan text to the menu scene and then also needed to make the money and load text to the fishing part and there i used the sessioncontroller to update the text using event when scene load it calls the update text function
image

In progress

Maby doing icons for the money and loan and changing how the ui looks

@Emiliontti
Copy link
Contributor

Emiliontti commented Nov 5, 2023

Completed Tasks

Make the fish catch on the hook

The fish needed to be caught on the hook. So, I made a child object for the hook, with no mesh, and a bigger collider. This collider would make collision entry, when the first fish puts it “next-target-location” inside the collider. Then the fish would take the transform of the hook, turn towards it and start swimming towards the hook and getting to a certain distance of it, stop. After this sequence the Minigame would start.

image

In the HookScript, the 2nd collider of the hook has a OnTriggerEnter, that detects the fishs next spawn target, and defines that fish as the “closestFish”, so we get a reference for the instance to the fish we’re dealing with.

image

In the FishScript I added the following methods, to get the target of the hook, and make that fish swim for the hook. The fish would stop, when it reached a certain distance from the hook, but also continue its journey, if the goingForHook -boolean was turned to false (i.e., the fish would swim away from the hook – used when the player resets the cast without catching the fish) 

image

Minigame

We needed to make the game a bit more interesting, and per our plan from the previous documentation, I started to make the minigame for that purpose.

image

The minigame consist of several UI elements. There’s a reference to the fish getting caught and getting the attributes (the speed of the fish icon, the amount of value needed and the “smoothness” of the movement of the fish icon) to the game. The code behind it makes it work in the following way:

  1. (the minigame gets triggers when a fish sets it next target inside the hooks collider, swims towards the hooks position and gets “caught”)
  2. The orange fish icon moves on it’s own inside the constrained blue area on the X-axis using math and update-method
    a. The fish derives it’s moving math from the fish that was previously caught on the hook. The scriptable objects that define the behaviour labelled as “Default”, “Lazy” and “Quick” pointing to the movement of the fish and also the max value of the progress bar.
  3. The green square can be moved by the player. The player can use their mouse, or the keyboard to move the square.
  4. When the square is on the fish, the green bar fills up. If it’s in the center of the fish icon, it fills it faster
  5. When the bar fills up completely, the minigame ends and the fish gets caught...

The referencing was a big problem when making the game in the script, because both the hook and the fish are both instantiated in the code. Also, the minigame-object itself is inactive before a fish is actually caught on the hook.

The following code is from the MinigameScript, and it gets the behaviour of the fish, and sets the slider max-value (makes the fish take longer to catch)

image

The update function makes the area move, as well as adjust the progress bar and calculates new positions for the fish-icon to travel to and makes it move.

image


The MinigameScript also houses the method to get the fish-behaviour from the caught fish scriptable objects:

image

Also, the moving the green square at the minigame is handled inside the MinigameScript’s MinigameMovement-method. The calculations make sure, that the square (and also the fish) stay inside of the designated area.

image

Because of the referencing issues (minigame being unactive until being made active by the fish catching the hook), the PlayerController acts as a link to pass the information of the fish caught on the hook. It also checks that the fish is close enough to the hook and not still swimming towards it, before starting the minigame.

image

The PlayerController also enables for the player to let the fish go from the hook, or it destroys the fish, when you complete the minigame (get max value on the progress bar)

image

In-progress

I’m working on doing the following tasks (quit game & return to home). So basically, I want to make it so that you can return from the game scene to the home scene, and also that you can quit them game from the home scene.
image

@TemkaUwU
Copy link
Contributor

TemkaUwU commented Nov 5, 2023

Completed

Made the hook stop

4

Made a new action in the player input action

image

This checks if the hook has already been cast and then disables its gravity to make it stop falling and turns on its collisions.

Made bobber and hook model

2 3

Went into blender and made these to replace the cube placeholders

In Progress

Make Splash screen scenes for Win, Lose and Catch fish
Screenshot 2023-11-05 234339

@Emiliontti
Copy link
Contributor

All doned! PDF Returned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants