Question by
Drackos_Flare · Sep 18, 2016 at 03:08 PM ·
scripting problemgravityscripting beginner
Movement script preventing gravity
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?
Comment
Answer by A13x231 · Sep 18, 2016 at 04:15 PM
Duplicate question, I answered the last one. http://answers.unity3d.com/questions/1245316/script-preventing-gravity-from-working.html