Quantcast
Viewing latest article 1
Browse Latest Browse All 10

Can't get gravity to work proberly (transform)

So I'm using a transform as a player with a camera following it. Gravity works fine at start, also when I hit the floor **mostly**. Sometimes the transform starts to rotate in these weird directions and suddenly my player can fly around rotating forever in the void. Here is a picture: ![alt text][1] [1]: http://img585.imageshack.us/img585/6055/unityproblem.png As you can see the cube had begun to rotate and floating. It's very random when it happens sometimes it works for just a while and then it screws up. Here is my code: var speed : float = 5.00; var yVelocity : float = 10.00; var gravity : float = 5.00; var onFloor : boolean = false; function Update () { plyMove(); if(onFloor == false) { transform.position.y -= gravity * Time.deltaTime; } else { return; } } function plyMove () { if(Input.GetKey("s")) { transform.Translate(-Vector3.forward * speed * Time.deltaTime); } if(Input.GetKey("w")) { transform.Translate(Vector3.forward * speed * Time.deltaTime); } if(Input.GetKey("d")) { transform.Rotate(Vector3(0,15,0) * Time.deltaTime); } if(Input.GetKey("a")) { transform.Rotate(Vector3(0,-15,0) * Time.deltaTime); } if(Input.GetKeyDown("space")) { transform.position.y += yVelocity * Time.deltaTime; } } function OnCollisionEnter(theCollision : Collision) { if(theCollision.gameObject.tag == "floor") { onFloor = true; } } function OnCollisionExit(afterCollision : Collision) { if(onFloor == true) { onFloor = false; } } also I believe it could be something about the rotation, but im not sure.

Viewing latest article 1
Browse Latest Browse All 10

Trending Articles



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