estimated time : 9 mn
ingredients needed : Unity, Playmaker
(this recipe is part of the footvolley game menu )
Adding a volley net sprite in the center of the field.
Fitting a collider to the sprite.
Adding new events if ball colliding with it.
00:02 Adding a wall object
In order to stop the player from invading the opponent’s field, we add a gameObject in the center of the field : the Net.
We add a box collider to it, and a rigidBody too with the “isKinematic” property set to true (to be sure that it doesn’t move when physics objects like ball & player collides with it).
Play with the box collider’s dimension to fit with the width of the field, once it fits we add a new Tag :”wall” to our “net” gameObject.
Now we’ll make something with this new “wall” tag; we’ll use it to stop the player’s slide if he collides with a wall.
The logic will be quite simple : when our player collides with a wall tag (the net, or any invisible wall from the external field), we’ll throw a “hitWall” event, that will send us to a temporary state that will just freeze the player for 0,3 sec; then return to the “release kick” state, closing the loop.
Add to our precedent invisible walls the “wall” tag too.Now that everything is set, we make changes in the Player1’s FSM :
In the the “Sliding” state, we add the “Trigger Event” action :
We trigger it with “on Trigger Enter” event, when colliding with the “wall” tag ; and for the “sent event”, we create a new event called “hitWall”.
Once created, we add the our new “hitWall” transition that will send us to a new created state “Freeze”.
In order to freeze the player we add in the “Freeze” state the action “Wait”, that we will set to 0,3 sec not to penalize too much a player hitting a wall at the end of his slide.
03:00 Adding the net child
We add a child gameObject to the “net”, that will contain the sprite and another collider.
We’ve used the collider in the parent gameObject to block the player. Now we’ll use this collider to block the ball. It’s a collider located in higher place on the Y axis, and will add more challenge for the player :
If the player is too close to the net while kicking a strong ball (meaning lower height) it will more likely hit the the net.
And if the player tries to send the ball too close to the net in the opponent field, it has great chances to hit the net too.
03:22 Adding the net sprite
We’ll use a sprite created for the occasion and store in our “images” folder. You can retrieve the “net” animated sprite and other ones as an exclusive content on my patreon , otherwise you can use any sprite of course to use it.
First don’t forget to convert the image as a sprite, then we add a sprite renderer component in our game object, and drag & drop our “net” sprite to it.
Then play with the position values to order it a little, and of course set the “sorting layer” to “Characters” to display the “net” above the rest.
04:53 Positionning the collider
Now the trickest part :
We add box collider component , check it as “Trigger”, and play with the size and with the heights to be a subtle obstacle to the ball; not too present tough. you have to play a bit with the size and Y heights to get it done. In my example I’ve set it’s center as (0, 0.93, 0) and for the size (0.45, 2.03, 4). We add the tag “net” to it.
06:29 Adding the net logic
In the soccer Ball FSM, on the “Kicked” state, we add another “Trigger Event” action , selecting “net” as a collide tag, and we create a new event :”touchNet”.
Next we create a new state “Net”, then in the “Kicked” state we add the “touchNet” transition, that we link to our “Net” state.
once we’re on the “Net” state, meaning by the way that we loose the point, we just copy for the moment the “Send Message” action of the grounded state, that basically sent back the ball to our field. It’s just for the moment, for testing purposes.
(note that, i’ve add a debug log action, but it’s only for myself, remember to erase the debug action as quick as possible as they’re evil, draining out too much ressources, and are easily forgotten )