- Home /
Question by
mauricefr · Jul 08, 2020 at 07:49 PM ·
2dscript.transform.position
Hello, I have been starting to programm just a short time ago, and I'm creating my first own Game: Jump And Run ( 2D ), and I wanted to ask how I can prevent that the Playerobject spins around?,Hello,
void Update() { float xEingabe = Input.GetAxis("Horizontal"); float yEingabe = Input.GetAxis("Vertical"); if (yEingabe < 0) { return; }
float xNeu = transform.position.x +
xEingabe * eingabeFaktor * Time.deltaTime;
if (xNeu > 8.3f)
{
xNeu = 8.3f;
}
if (xNeu < -8.3f)
{
xNeu = -8.3f;
}
float yNeu = transform.position.y +
yEingabe * eingabeFaktor * Time.deltaTime;
if (yNeu < -5)
{
yNeu = -4.4f;
}
transform.position = new Vector3(xNeu, yNeu, 0);
,
Comment
What do you mean by "spins around"? As in, the object is rotating? In the code snippet you provided the only thing that gets modified is the object's position, so the problem most likely lies somewhere else.
Answer by mauricefr · Jul 09, 2020 at 07:46 PM
Oh, sorry, if I didn't describet it clearly enough. The gamObject didn't spin around every time, but it spins around, if you don't come with the complete lower side on a Plattform.
Your answer
![](https://koobas.hobune.stream/wayback/20220613002755im_/https://answers.unity.com/themes/thub/images/avi.jpg)