Goal¶
In this section, you will implement the soccer goal logic.
- Create a new script
SoccerGoaland add it to theGoalGameObject. - Add a
StaticFrameSyncBehaviourcomponent to theGoaland set itsOwntoPlayer1.
Replace the contents in the SoccerGoal script with the following.
using SocketWeaver.FPhysics3D;
using UnityEngine;
using SocketWeaver.FrameSync;
using SocketWeaver.FixedMath;
namespace SWExample.Soccer
{
public class SoccerGoal : MonoBehaviour, IFrameSyncOnStart
{
FrameSyncBehaviour _frameSyncBehaviour;
public void OnStart(FrameSyncBehaviour frameSyncBehaviour)
{
_frameSyncBehaviour = frameSyncBehaviour;
}
public void OnFTriggerEnter(FCollider3D fCollider)
{
FrameSyncUpdateType updateType = _frameSyncBehaviour.game.updateType;
int frameNumber = _frameSyncBehaviour.game.frameNumber;
Debug.Log($"{fCollider.name} trigger enter, updateType={updateType} frameNumber={frameNumber}");
//score
FrameSyncPlayer player = _frameSyncBehaviour.owner;
SoccerGameFlow gameFlow = FindObjectOfType<SoccerGameFlow>();
gameFlow.PlayerScored(player);
}
}
}
Trigger events¶
To receive the trigger events of the Goal collider:
- Enabled
Eventsof theFRigidbody3Dcomponent of theGoalGameObject - Add an event listener to the
OnTriggerEnterevent, and selectOnFTriggerEnter.

Physics Layer Collision Matrix¶
FPhysics supports the Unity physics layer collision matrix. You will create layers and change their collision matrix so the Goal collider only collides with the Ball.
- Create the following layers and assign the
Car, theBalland theGoalto their layers
| Layer Name | GameObject | Description |
|---|---|---|
| SoccerBall | Ball | Collides with the cars, the goals, and the Arena |
| SocerCars | Cars | Collides with other cars, the ball, and the Arena |
| SoccerGoal | Goals | Collides with the ball only |
- Select
Edit->Project Settings->Physics. - Update the
Layer Collision Matrixto the following: