Hello! First time user here. So, I have no idea what I’m doing, but we’ve all been there at one point right?
For some reason, My character isn’t affected by gravity when this is active:
float xPos = transform.position.x + (Input.GetAxis("Horizontal") * moveSpeed);
playerPos = new Vector3(Mathf.Clamp(xPos, -50, 50), 0, 0);
transform.position = playerPos;
When this part of the script is gone, the Gravity suddenly works, but I can’t move (as expected).
In the Rigidbody, “Use Gravity” is checked and “Is Kinematic” is unchecked.
This is the entire script:
using UnityEngine;
using System.Collections;
public class IceDeeMovement : MonoBehaviour {
public float moveSpeed = 0.3f;
public Vector3 playerPos;
void Update()
{
float xPos = transform.position.x + (Input.GetAxis("Horizontal") * moveSpeed);
playerPos = new Vector3(Mathf.Clamp(xPos, -50, 50), 0, 0);
transform.position = playerPos;
}
}
Can someone tell me what’s wrong?