Quantcast
Channel: Questions in topic: "issue"
Viewing all articles
Browse latest Browse all 827

Why my Player Movement doesn't work

$
0
0
Now, I am new to unity, so a simple answer will help me a lot. I have an object in the scene and it has 4 components ( Transform, Animator, Character Controller, Script). my Player Movement doesn't work. Any help will really be appreciated. using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMotor : MonoBehaviour { private const float LANE_DISTANCE = 3.0f; // Movement private CharacterController controller; private float jumpForce = 4.0f; private float gravity = 12.0f; private float verticalVelocity; private float speed = 7.0f; private int desiredLane = 1; // 0 = Left, 1 = Middle, 2 = Right private void Start() { controller = GetComponent(); } private void Update() { // if (Input.GetKeyDown(KeyCode.LeftArrow)) MoveLane(false); if (Input.GetKeyDown(KeyCode.RightArrow)) MoveLane(true); // Vector3 targetPosition = transform.position.z * Vector3.forward; if (desiredLane == 0) targetPosition += Vector3.left * LANE_DISTANCE; else if (desiredLane == 2) targetPosition += Vector3.right * LANE_DISTANCE; // Vector3 moveVector = Vector3.zero; moveVector.x = (targetPosition - transform.position).normalized.x * speed; moveVector.y = -0.1f; moveVector.z = speed; // controller.Move(moveVector * Time.deltaTime); } private void MoveLane(bool goingRight) { if (!goingRight) { desiredLane--; if (desiredLane == -1) desiredLane = 0; } else { desiredLane++; if (desiredLane == 3) desiredLane = 2; } } }

Viewing all articles
Browse latest Browse all 827

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>