- Home /
all Rigid body's slow down and speed up
hey!
I have a problem with my game: All rigid body's slow down and speed up when I play the game. Sometimes it's like nothing ever happened, and sometimes all the rigid body's react slow!
are you adding force or moving your rigidbodies within FixedUpdate?
Can you post your script? Is it posible something else is doing something to the rigidbodys?
I only use a script for moving the player, wich is just simple adding force on the z-axis and limiting the force of the player.
Answer by clunk47 · Jul 25, 2013 at 06:28 AM
You could either do some homework on rigidbody characters, or just use a CharacterController. Unity installer has an asset pack you can import, makes things easy, unless you're wanting to do something different because you want to learn. If that's the case, here's something to get you started. This exmaple is written in C-Sharp.
//RigidbodyCharacterController.cs
using UnityEngine;
using System.Collections;
public class RigidbodyCharacterController: MonoBehaviour {
public int turnSpeed;
public int moveSpeed;
public int jumpForce;
bool onGround;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
transform.Rotate( 0, h * turnSpeed * Time.deltaTime, 0 );
Vector3 moveAmount = transform.forward * v * moveSpeed;
rigidbody.MovePosition( transform.position + moveAmount * Time.deltaTime );
rigidbody.velocity = moveAmount + Vector3.Scale(rigidbody.velocity, new Vector3(0,1,0));
if (onGround && Input.GetKey(KeyCode.Space))
{
rigidbody.AddForce( transform.up * jumpForce, ForceMode.Impulse );
onGround = false;
}
}
void OnCollisionEnter() {
onGround = true;
}
}
Thanks! I didn't use the character controller because I wanted to create it myself. I enjoy making that a lot more! thanks for you answer! It solved the problem! Thanks!
You're very welcome. Glad to see someone wanting to learn rather than just using built in controllers or just demanding that people write them scripts lol. $$anonymous$$ade my day a bit better. Have a good one dude!
Yea, I don't like taking other people's scripts. ins$$anonymous$$d I take pieces of it and trying to understand it and modify it. That's a lot more fun and you learn very good by doing that!
Gets easier and easier brotha. Have a good night man, I'm outski.
Your answer
Follow this Question
Related Questions
Apply force then slowly back off 4 Answers
My objects are falling to slowly when a rigidbody is attached, cab you help? 9 Answers
Low framerate on physics initialization. 0 Answers
Fast moving object not detect collision 3 Answers
slow addforce 1 Answer