Force receiver missing

My Force Receiver field isn’t showing up in the Player State Machine. I’m getting the following error: Assets\Scripts\StateMachines\Player\PlayerBaseState.cs(16,22): error CS1061: ‘PlayerStateMachine’ does not contain a definition for ‘Controller’ and no accessible extension method ‘Controller’ accepting a first argument of type ‘PlayerStateMachine’ could be found (are you missing a using directive or an assembly reference?)

Not quite sure what’s going on here. Here’s the Player Base State code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class PlayerBaseState : State
{
    protected PlayerStateMachine stateMachine;

    public PlayerBaseState(PlayerStateMachine stateMachine)
    {
        this.stateMachine = stateMachine;
    }

    protected void Move(Vector3 motion, float deltaTime)
    {
        stateMachine.Controller.Move((motion + stateMachine.ForceReceiver.Movement) * deltaTime);
    }
}

And the Player State Machine:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerStateMachine : StateMachine
{
    [field: SerializeField] public InputReader InputReader { get; private set; }

    [field: SerializeField] public CharacterController CharacterController { get; private set; }

    [field: SerializeField] public float FreeLookMovementSpeed { get; private set; }

    [field: SerializeField] public float RotationDamping { get; private set; }

    [field: SerializeField] public Animator Animator { get; private set; }

    [field: SerializeField] public Targeter Targeter { get; private set; }

    [field: SerializeField] public ForceReceiver ForceReceiver { get; private set; }


    public Transform MainCameraTransform { get; private set; }

    void Start()
    {
        MainCameraTransform = Camera.main.transform;

        SwitchState(new PlayerFreeLookState(this));
    }

}

In your Player State Machine, your CharacterController is named CharacterController, but in your PlayerBaseState, you’re calling stateMachine.Controller.Move

Try changing this to

stateMachine.CharacterController.Move((motion + stateMachine.ForceReceiver.Movement));
``

Damn, don’t know how I missed that. Thanks, that worked.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms