- Home /
How do I keep my sprite standing upright?,
I'm a beginner in unity and I'm in the middle of making a 2d platformer, I was able to make my character move but when it hits the edge of a platform, my character tips over and can't get back up. I don't know if it's because of the components on my character, or if it's because of the script i'm using. if it's the latter, then here's the script for reference.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player : MonoBehaviour {
float speed = 1.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
var move = new Vector3 (Input.GetAxis ("Horizontal"), Input.GetAxis ("Vertical"), 0);
transform.position += move * speed * Time.deltaTime;
}
}
Without gravity acting on the character, the only force acting on it is your movement, so when it hits the edge of the platform, that force will likely be converted to angular momentum so it tips. You can add a Rigidbody2D component to the character to ensure gravity is acting on the character so it doesn't tend to tip. It should follow a more parabolic path off platforms, as you would see if you'd roll a toy car off a desk.
Answer by ZachJohnson · May 11, 2018 at 12:35 AM
Do you use a rigidbody? If so, you can freeze rotation as a simple fix. This is under the object's rigidbody component.
Your answer
Follow this Question
Related Questions
Do you tend to have scripts to mark prefabs 1 Answer
Get specific component on gameobject after order in inspector 1 Answer
Deactivate an object - and all scripts in that object deactivated? 1 Answer
how can i access to the scripts which have same name and were attached to the same gameobject. 2 Answers