- Home /
Question by
QuincyOnIce · Jan 01, 2020 at 12:10 AM ·
charactercontrollercharacter controllercharacter movementdash
Character Controller based 'dash' function moves strangely in one direction, despite values seemingly being correct.
Hello, I'm working on a pretty simple dash function for my character controller. But there's a weird problem.
In the first picture, the yellow arrow represents actual movement while the green one represents what I want and expect it to do. As you can see, it moves diagonally instead of straight. In the second, it moves exactly as I want it to, In a straight line backwards, as represented by the green arrow.
private void Dash(Vector3 Direction)
{
GameObject WarpClone = Instantiate(gameObject);
WarpClone.transform.position = transform.position;
Destroy(WarpClone.GetComponent<CharacterMovement>());
Destroy(WarpClone.GetComponent<CharacterController>());
Destroy(WarpClone.GetComponent<Animator>());
foreach (Transform child in WarpClone.GetComponentsInChildren<Transform>())
{
Destroy(child.GetComponent<Collider>());
SkinnedMeshRenderer[] SMRs = WarpClone.GetComponentsInChildren<SkinnedMeshRenderer>();
MeshRenderer[] MRs = WarpClone.GetComponentsInChildren<MeshRenderer>();
foreach (SkinnedMeshRenderer SMR in SMRs)
{
SMR.material = warpMaterial;
}
foreach (MeshRenderer MR in MRs)
{
MR.material = warpMaterial;
}
}
Destroy(WarpClone, 100f);
CC.Move(Direction * dashStrength);
Here's the code for actually moving and creating the 'silhouettes'.
private void DashFuncW()
{
if (Time.realtimeSinceStartup - timeOfFirstButton < DoublePressSpan && Input.GetKeyDown(KeyCode.W) && firstButtonPressed)
{
Dash(transform.forward);
firstButtonPressed = false;
timeOfFirstButton = 0f;
}
if (Input.GetKeyDown(KeyCode.W))
{
timeOfFirstButton = Time.realtimeSinceStartup;
firstButtonPressed = true;
}
}
private void DashFuncS()
{
{
if (Time.realtimeSinceStartup - timeOfFirstButton < DoublePressSpan && Input.GetKeyDown(KeyCode.S) && firstButtonPressed)
{
Dash(-transform.forward);
firstButtonPressed = false;
timeOfFirstButton = 0f;
}
if (Input.GetKeyDown(KeyCode.S))
{
timeOfFirstButton = Time.realtimeSinceStartup;
firstButtonPressed = true;
}
}
And here's the code to get the double tap input.
I really can't figure out why it behaves like this; since the backwards one works fine but the front one doesn't, even though they use practically the same values. Any help at all would be appreciated.
Comment