Quantcast
Channel: Questions in topic: "ios"
Viewing all articles
Browse latest Browse all 4709

AddForce doesn't work when used with velocity

$
0
0
Hi, I'm very new to Unity and I can't get around this weird problem. I have a top down iOS game where you roll a ball around using the accelerometer and then tap to jump. I'm using rigidbody.AddForce to jump in the Y direction and the rolling movement is on the XZ plane. What happens is that when I tap, the ball jumps but not that high and it falls to the ground very slowly. This is very odd because if I use rigidbody.AddForce() instead of rigidbody.velocity to roll the ball around, the jump works really well and it also jumps higher than before. Any ideas about what's going on here? I double checked my colliders and Rigidbody settings and all seems fine, and it even works if I don't use rigidbody.velocity, but I feel that's the best way to roll the ball around in the game so I have to use it. BTW, the reason I use GetMouseButton(0) is so that I can try it out the jump in the Editor with my mouse. Same command accepts iOS touch also. Any help is appreciated, This is my code: moveDirection.x = Input.acceleration.x; moveDirection.z = Input.acceleration.y; if (moveDirection.sqrMagnitude > 1f) { moveDirection.Normalize(); } rigidbody.velocity = moveDirection * Time.fixedDeltaTime * moveSpeed * speedFac; if (Input.GetMouseButton(0)) { Debug.Log("touched"); if (isGrounded) { rigidbody.AddForce(0f, jumpforce * Time.FixedDeltaTime, 0f, ForceMode.Impulse); isGrounded = false; } }

Viewing all articles
Browse latest Browse all 4709

Trending Articles



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