Right now, I'm freezing the player by making his Rigidbody go to sleep at the start and wake up at the end of a conversation with Dialogue System events.
The problem is, when he starts a conversation in the middle of a jump he is frozen in the air and it looks weird (because his animation state goes to idle also). But if I don't freeze his Rigidbody, he slides to Narnia.
Is there a way to keep his gravity falling to the ground but still keep him from moving/sliding during dialogue?
Thank you
How to Stop Player from Sliding Forward in Conversation
-
- Posts: 60
- Joined: Thu Mar 24, 2022 12:07 am
Re: How to Stop Player from Sliding Forward in Conversation
Hi,
You can add a script like this to the player:
StopCharacterVelocity.cs
Then configure Dialogue System Events to call StopCharacterVelocity.Stop:
You can also modify the script to do the same thing without having to set up Dialogue System Events:
StopCharacterVelocity.cs
If you're making a 2D game, use Rigidbody2D instead of Rigidbody, and use Vector2.zero instead of Vector3.zero.
You can add a script like this to the player:
StopCharacterVelocity.cs
Code: Select all
using UnityEngine;
public class StopCharacterVelocity : MonoBehaviour
{
public void Stop()
{
var rb = GetComponent<Rigidbody>();
if (rb != null)
{
rb.velocity = rb.angularVelocity = Vector3.zero;
}
}
}
You can also modify the script to do the same thing without having to set up Dialogue System Events:
StopCharacterVelocity.cs
Code: Select all
using UnityEngine;
public class StopCharacterVelocity : MonoBehaviour
{
public void OnConversationStart(Transform actor)
{
Stop();
}
public void Stop()
{
var rb = GetComponent<Rigidbody>();
if (rb != null)
{
rb.velocity = rb.angularVelocity = Vector3.zero;
}
}
}
If you're making a 2D game, use Rigidbody2D instead of Rigidbody, and use Vector2.zero instead of Vector3.zero.
-
- Posts: 60
- Joined: Thu Mar 24, 2022 12:07 am
Re: How to Stop Player from Sliding Forward in Conversation
Thank you very much Greatest customer support on EarthTony Li wrote: ↑Mon Apr 11, 2022 5:05 pm Hi,
You can add a script like this to the player:
StopCharacterVelocity.csThen configure Dialogue System Events to call StopCharacterVelocity.Stop:Code: Select all
using UnityEngine; public class StopCharacterVelocity : MonoBehaviour { public void Stop() { var rb = GetComponent<Rigidbody>(); if (rb != null) { rb.velocity = rb.angularVelocity = Vector3.zero; } } }
stopCharacterVelocity.png
You can also modify the script to do the same thing without having to set up Dialogue System Events:
StopCharacterVelocity.csCode: Select all
using UnityEngine; public class StopCharacterVelocity : MonoBehaviour { public void OnConversationStart(Transform actor) { Stop(); } public void Stop() { var rb = GetComponent<Rigidbody>(); if (rb != null) { rb.velocity = rb.angularVelocity = Vector3.zero; } } }
If you're making a 2D game, use Rigidbody2D instead of Rigidbody, and use Vector2.zero instead of Vector3.zero.