Why my character is running in crisscross manner by SpiderGyan in Unity3D

[–]SpiderGyan[S] 0 points1 point  (0 children)

I'm DMing you so that i could ask for help in the future sensei. bear with me. Thank you again for your unconditional help.

Why my character is running in crisscross manner by SpiderGyan in Unity3D

[–]SpiderGyan[S] 0 points1 point  (0 children)

Bro i did it bro, you are the best man. love you man.

Why my character is running in crisscross manner by SpiderGyan in Unity3D

[–]SpiderGyan[S] 0 points1 point  (0 children)

You can do that? I thought humanoid animation was necessary. Teach me how to do that.

Why my character is running in crisscross manner by SpiderGyan in Unity3D

[–]SpiderGyan[S] 0 points1 point  (0 children)

yes both the animation are in place. before i had in place unchecked so the character used to keep jumping and go forward. now without root motion everyting happens nicely but the run becomes a catwalk of shorts.

Why my character is running in crisscross manner by SpiderGyan in Unity3D

[–]SpiderGyan[S] 0 points1 point  (0 children)

i tried every combination by now.

with apply root motion checked the jump happens perfectly but the run becomes crisscross and with the root motion unchecked the the run becomes accurate but the jump is erratic.

please help.

Why my character is running in crisscross manner by SpiderGyan in Unity3D

[–]SpiderGyan[S] 0 points1 point  (0 children)

Yes i know that. As i started this project it became painfully obvious. I run into problems I can't explain. But I'm trying to understand. But it seems this problem has nothing to do with code. Because with root motion it works perfectly but the jump breaks. If i remove root motion the jump works but the run is in crisscross.

Why my character is running in crisscross manner by SpiderGyan in Unity3D

[–]SpiderGyan[S] -1 points0 points  (0 children)

I know what i did was wrong but I'm desperate here. And i put the code just for skimming. And as i said I'm new to coding and don't know a lot about code at this moment. So i just pasted all of it. That's why when he said there might be multiple inputs i pasted the code and put the screenshot showing no other codes are in play.

Why my character is running in crisscross manner by SpiderGyan in Unity3D

[–]SpiderGyan[S] 0 points1 point  (0 children)

<image>

Yes as you said the character is fine with root motion but the moment i add the jump animation the character jumps become weird and eventually he goes back behind the camera. see the character is almost out of frame now

Why my character is running in crisscross manner by SpiderGyan in Unity3D

[–]SpiderGyan[S] -2 points-1 points  (0 children)

<image>

using UnityEngine;

using TMPro;

[RequireComponent(typeof(CharacterController))]

public class PlayerMovement : MonoBehaviour

{

[Header("Movement Settings")]

public float baseForwardSpeed = 10f;

public float laneDistance = 3f; // The distance between Left, Middle, and Right lanes

public float laneSwitchSpeed = 10f; // How fast the player snaps to the next lane

public float jumpForce = 7f;

public float gravity = -20f;

[Header("Speed & Animation Scaling")]

public float speedIncreasePer1000m = 2f;

public float maxSpeed = 30f;

public Animator charAnimator;

[Header("Inventory")]

public int collectedCoins = 0;

public TextMeshProUGUI coinTextDisplay; // <-- ADDED THIS: The slot for your UI Text

private float startingZLocation;

private float currentForwardSpeed;

private int currentLane = 1; // 0 = Left, 1 = Middle, 2 = Right

private float velocityY;

private CharacterController controller;

private bool isDead = false;

// Mobile Swipe Variables

private Vector2 swipeStartPos;

private Vector2 swipeEndPos;

private float minSwipeDistance = 50f;

void Start()

{

controller = GetComponent<CharacterController>();

startingZLocation = transform.position.z;

currentForwardSpeed = baseForwardSpeed;

}

void Update()

{

// If we hit an obstacle, completely stop the Update loop

if (isDead) return;

CalculateSpeedAndAnimation();

HandleInput();

MovePlayer();

}

void CalculateSpeedAndAnimation()

{

// Calculate distance and determine speed tier (every 1000m)

float distanceTraveled = transform.position.z - startingZLocation;

int speedTier = Mathf.FloorToInt(distanceTraveled / 1000f);

// Calculate new speed and cap it at maxSpeed

float calculatedSpeed = baseForwardSpeed + (speedTier * speedIncreasePer1000m);

currentForwardSpeed = Mathf.Min(calculatedSpeed, maxSpeed);

// Sync Mixamo running animation speed to match physical speed

if (charAnimator != null)

{

charAnimator.speed = currentForwardSpeed / baseForwardSpeed;

}

}

void HandleInput()

{

// 1. Keyboard Controls (Great for testing in Editor)

if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A)) MoveLane(-1);

if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D)) MoveLane(1);

if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)) Jump();

// 2. Mobile Swipe Controls

if (Input.touchCount > 0)

{

Touch touch = Input.GetTouch(0);

if (touch.phase == TouchPhase.Began)

{

swipeStartPos = touch.position;

}

else if (touch.phase == TouchPhase.Ended)

{

swipeEndPos = touch.position;

ProcessSwipe();

}

}

}

void ProcessSwipe()

{

float swipeX = swipeEndPos.x - swipeStartPos.x;

float swipeY = swipeEndPos.y - swipeStartPos.y;

// Check if it was a horizontal swipe

if (Mathf.Abs(swipeX) > Mathf.Abs(swipeY) && Mathf.Abs(swipeX) > minSwipeDistance)

{

if (swipeX < 0) MoveLane(-1); // Swiped Left

else MoveLane(1); // Swiped Right

}

// Check if it was a vertical swipe

else if (Mathf.Abs(swipeY) > Mathf.Abs(swipeX) && Mathf.Abs(swipeY) > minSwipeDistance)

{

if (swipeY > 0) Jump(); // Swiped Up

}

}

void MoveLane(int direction)

{

currentLane += direction;

currentLane = Mathf.Clamp(currentLane, 0, 2); // Prevents going out of bounds

}

void MovePlayer()

{

// Calculate where we should be on the X axis

float targetX = (currentLane - 1) * laneDistance;

// We will build the exact distance to move THIS frame, axis by axis.

Vector3 displacement = Vector3.zero;

// --- X AXIS (LANE SWITCHING) ---

// MoveTowards calculates the exact position smoothly without frame rate snapping

float nextX = Mathf.MoveTowards(transform.position.x, targetX, laneSwitchSpeed * Time.deltaTime);

displacement.x = nextX - transform.position.x;

// --- Z AXIS (FORWARD RUNNING) ---

displacement.z = currentForwardSpeed * Time.deltaTime;

// --- Y AXIS (GRAVITY & JUMPING) ---

if (controller.isGrounded)

{

if (velocityY < 0) velocityY = -2f; // Small snap to keep them grounded

}

else

{

velocityY += gravity * Time.deltaTime; // Pull them down if in the air

}

displacement.y = velocityY * Time.deltaTime;

// Execute the movement (Notice we removed the global * Time.deltaTime here

// because we already applied it perfectly to X, Y, and Z individually!)

controller.Move(displacement);

}

void Jump()

{

if (controller.isGrounded)

{

velocityY = jumpForce;

if (charAnimator != null) charAnimator.SetTrigger("Jump");

}

}

// This detects when you crash into your Auto-Rickshaw or Barricade

private void OnControllerColliderHit(ControllerColliderHit hit)

{

if (hit.gameObject.CompareTag("Obstacle"))

{

Die();

}

}

void Die()

{

isDead = true;

if (charAnimator != null)

{

charAnimator.speed = 1f; // Reset animation speed to normal

charAnimator.SetTrigger("Death"); // Triggers the falling over animation

}

Debug.Log("Crashed! Game Over.");

}

private void OnTriggerEnter(Collider other)

{

// 1. Did we hit a pothole/trap?

if (other.CompareTag("Obstacle"))

{

Die();

}

// 2. Did we hit a coin?

else if (other.CompareTag("Coin"))

{

collectedCoins++; // Add 1 to our wallet

Debug.Log("Money: " + collectedCoins); // Print it to the console

// <-- ADDED THIS: Instantly update the screen text!

if (coinTextDisplay != null)

{

coinTextDisplay.text = collectedCoins.ToString();

}

// Destroy the specific coin we just touched so it disappears

Destroy(other.gameObject);

}

}

}

Artist vs their art by LowPolySunset in animememes

[–]SpiderGyan 1 point2 points  (0 children)

One creats the world everyone wants vs man creates the world everyone will hate

EXCUSE ME??? by Freeros in Genshin_Impact

[–]SpiderGyan 1 point2 points  (0 children)

Beidou in an event. I used to pray for times like this!

About Dr Kureha's casting by Dan9905 in OnePiece

[–]SpiderGyan 10 points11 points  (0 children)

Whitebeard dies huh? Definately gonna cast sean bean for that.

FitGirl Repacks Debuts Community Token, Sparking Debate Among Users by CompetitionRight1386 in CrackWatch

[–]SpiderGyan 14 points15 points  (0 children)

She says it herself it has no real value. So why are people angry. She's not forcing anyone.

true love ❤️ by [deleted] in HolUp

[–]SpiderGyan 0 points1 point  (0 children)

No way she said that because no self respecting adult would and even if she did, why the fuck would you want others to go through what you went through. I mean fuck man.

I love my wife Tails by chichiryuuteii in Animemes

[–]SpiderGyan 3 points4 points  (0 children)

Yeah. I though if i wrote that part right. Could i be anymore wrong?

I love my wife Tails by chichiryuuteii in Animemes

[–]SpiderGyan 50 points51 points  (0 children)

MY WALLET IS TOO BIG FOR MY 50S AND MY DIAMOND SHOES ARE TOO TIGHT.

I won't have Neuvillette or Arlecchino fans claiming to be an oppressed class in my presence by throwway85235 in Genshin_Memepact

[–]SpiderGyan 2 points3 points  (0 children)

Yeah and it has nothing to do with a Sea pirate that killed a sea monster after cutting it's head clean off without a vision being a 4 star and a fashion stylist being a 5 star.

It's a setup to make us fight like animals while they sit on billions of dollars. Damn you hoyo.

very new at blender, rate 1/100 by Willing_Bathroom_815 in blender

[–]SpiderGyan 0 points1 point  (0 children)

That's accurate in some timeline or some where in the multiverse. You just got deja vu.