Footy Volley gameplay tuning -part 2

estimated time : 13 mn
ingredients needed : Unity ,Playmaker
(this recipe is part of the footvolley game menu )

Okay, let’s check our plans; We now need to reduce our circle collider radius while we keep our shoot button pressed, as well as increasing a force value to hit back the ball.

00:04 Creating variables

The scaleSpeed float, will contains the speed at which our circle collider will decrease. Create scaleSpeed float value in player FSM variables, set it to -0.05.
The origin_colliderScale float, will contains the default value of our original collider X scale gameObject. Create origin_colliderScale float in player FSM variables.
In Player Setup state, create a getScale action and store its X scale in our new created variable origin_colliderScale.

The curr_scale will contains the actual X scale of our collider radius.
In player FSM variables, create the curr_scale float.
In Idle state, we’ll set our start value of curr_scale  by the setFloat action and set up to our original_colliderScale. Which contains the X scale float of our default radius.

Scaling our collider

Now while we shrink our collider while our shot button’s pressed.
We’ll do that in our isKicking state, by getting our current collider scale first.
Then we add the scaleSpeed value (which is a negative value) to our current collider scale.
And we assure, by adding some code in our playerController script, that our collider don’t shrink too much with a loop.

We have several ways to do this :
Wrote all the code in playmaker by adding lines on our isKickingState(a line to add the values between them, another to set the scale..), but it will be too messy to read afterwards.
Or wrote all code in PlayerController script, but by doing this we’ll not see that in our playmakerState that some changes will be happening in our script, and misses some things while looking only at playmaker states.

What I like to do, is to hard script the code, but with a little call to a function in Playmaker that will allows me to see later that in this state, there’ll be some calls in my code.

02:46 Calling function from playmaker

So we go in our Player’s isKicking state and add the action Send Message.
We send our message in our same GameObject (Player1), as our Player1 contains the playerController script, the script will be able to intercept the call. And we name the method that we want to call “ReduceColliderON”.
Now we have to create this method on our script.

Coding time, have a look at the changes mades in the PlayerController script, they’re all have comments:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HutongGames.PlayMaker;
public class playerController : MonoBehaviour {
public int playerSpeed;
public PlayMakerFSM MyFsm;
private FsmBool canMove;
//here we declare the wanted values, curr_scale and scaleSpeed
//in order to add them in the update loop
private FsmFloat curr_scale,scaleSpeed;
//we create a boolean too, that's what the call is made for : activate the bool
private bool isReducingCollider = false;
private CharacterController _controller;
void Awake()
MyFsm = this.GetComponent<PlayMakerFSM>();
// Use this for initialization
void Start () {
_controller = GetComponent<CharacterController>();
canMove = MyFsm.FsmVariables.FindFsmBool("canMove");
//now we retrieve our vars
curr_scale = MyFsm.FsmVariables.FindFsmFloat("curr_scale");
scaleSpeed = MyFsm.FsmVariables.FindFsmFloat("scaleSpeed");
//This is the call made by playmaker
void ReduceColliderON(){
isReducingCollider = true;
void Update () {
Vector3 move = new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
_controller.SimpleMove(move * playerSpeed);
//Now as we set the isReducingCollider to true by our call, we have our call to
//our reduce collider script on every frame.
if(isReducingCollider) ShrinkCollider();
void ShrinkCollider(){
//we shrink the scale by adding to the current scale the scaleSpeed value (which is a negative one)
curr_scale.Value = curr_scale.Value + scaleSpeed.Value;
//assure than our collider doesn't shrink too much
if(curr_scale.Value <=2)
curr_scale.Value = 2;

07:00 Set scale action

Once we’ve modified the code, we return to the isKicking state to add the action SetScale. We set the X&Y scale value to our current_scale value. And we apply it on every frames.

Now we go back to our idle state to retrieve a normal collider scale when releasing our button.
We add the setScale action too, and we enter the same current_scale value, because we set the current_scale value to original_scale one line before.

08:31 Get back to normal

Then we made a little call to a new function “ReduceColliderOFF”, that will set our boolean to false again.

09:17 Increasing power

We now have to increase a power value.
so let’s create a power float value in FSM window. then we declare it again in our playerController script, and create a powerUnit value too, it will be this value that will be added to our power; make it as a serializedField, like this we can set it up and modify it in the Unity Editor.

[cc lang=”csharp”] private FsmFloat curr_Power;
[SerializeField] private float powerUnit;

then we’re pointing at the fsm value at start

[cc lang=”csharp”] curr_Power = MyFsm.FsmVariables.FindFsmFloat(“curr_Power”);

and increase it into our shrinking loop.

[cc lang=”csharp”]

void shrinkCollider(){
curr_scale.Value = curr_scale.Value + scaleSpeed.Value;
curr_Power.Value =curr_Power.Value +powerUnit;
if(curr_scale.Value <= 2)
curr_scale.Value = 2;


11:32 Restore power value

Don’t forget to come back to a normal power value, by setting up our curr_power value to 0 in our Idle State with the action SetFloat.


Leave a Reply