Hello,
I do not want my player to have the option of starting dialogue if they are jumping.
Is there a way I can check for "if(playerIsGrounded)" before giving the dialogue option?
Dialogue Only When Player Is Grounded
Re: Dialogue Only When Player Is Grounded
Hi,
Here are two different ideas for doing that:
1. Disable the ProximitySelector component while jumping. (This is probably the simplest solution.)
2. Or make a subclass of ProximitySelector and override UseCurrentSelection(). Example:
Here are two different ideas for doing that:
1. Disable the ProximitySelector component while jumping. (This is probably the simplest solution.)
2. Or make a subclass of ProximitySelector and override UseCurrentSelection(). Example:
Code: Select all
public override void UseCurrentSelection()
{
if (playController.playerIsGrounded)
{
base.UseCurrentSelection();
}
}
- PayasoPrince
- Posts: 104
- Joined: Thu Jan 27, 2022 6:47 pm
Re: Dialogue Only When Player Is Grounded
Thanks for the follow up, Tony!
I ended up going the route of making a subclass for the ProximitySelector.
This way, I was able to integrate the dialogue system into my custom PlayerController Class. My player states are driven by a state machine. I created a new speaking state that disables movement and sets the animator to play the Idle animation.
So, to hook this all up, I did this:
then, I added an OnConversationEnd() event to leave the speaking state and gain control by returning to the idle state.
This worked, however, it created a problem. I didn't realize that "UseCurrentSelection()" would always execute. Even if you weren't in range of a usable NPC. So when I pressed the firekey at a random point in the map, my player would always enter the speaking state and get stuck with no control.
To fix this, I added the condition
All together, it looks like this:
Seems to be working perfectly now. However, I would like to make sure its future proof.
Are there any issues with how I am currently doing this?
I ended up going the route of making a subclass for the ProximitySelector.
This way, I was able to integrate the dialogue system into my custom PlayerController Class. My player states are driven by a state machine. I created a new speaking state that disables movement and sets the animator to play the Idle animation.
So, to hook this all up, I did this:
Code: Select all
if (playerController.myController.isGrounded)
{
playerController.stateMachine.ChangeState<HDialogueState>();
base.UseCurrentSelection();
}
This worked, however, it created a problem. I didn't realize that "UseCurrentSelection()" would always execute. Even if you weren't in range of a usable NPC. So when I pressed the firekey at a random point in the map, my player would always enter the speaking state and get stuck with no control.
To fix this, I added the condition
Code: Select all
"if ((currentUsable != null) && currentUsable.enabled && (currentUsable.gameObject != null) && (Time.time >= timeToEnableUseButton))"
Code: Select all
public override void UseCurrentSelection()
{
if ((currentUsable != null) && currentUsable.enabled && (currentUsable.gameObject != null) && (Time.time >= timeToEnableUseButton))
{
if (playerController.myController.isGrounded)
{
playerController.stateMachine.ChangeState<HDialogueState>();
base.UseCurrentSelection();
}
}
}
Are there any issues with how I am currently doing this?
Re: Dialogue Only When Player Is Grounded
I don't foresee any issues. That should be totally future proof.