This question was
closed Nov 24, 2017 at 07:24 AM by
awts202 for the following reason:
Problem is not reproducible or outdated
Question by
awts202 · Apr 25, 2017 at 02:54 PM ·
terraincollidersbug-perhapsball
Issue when terrain or ground is not plane, a bug or programming?
I have a sphere object and it's jumping is really weird. I really don't know if it has to do with my code or just a bug. When my sphere jump on a plane ground my jumping works nice, but if i edit and put a hill on the terrain i got a short jump. As long as the mesh is not plane it will short jump and I don't really know why. This sphere might be retarded. Here's my code.
public class BasicMovement : MonoBehaviour {
public float speed = 30;
public float speedSlowdown = 5;
public float desiredMaxSpeed = 5;
public float jumpHeight = 8.0f;
private Rigidbody rb;
private bool grounded;
private bool isjumping;
private bool isMoving;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void OnCollisionStay(Collision col)
{
grounded = true;
isMoving = true;
}
void OnCollisionExit(Collision col)
{
grounded = false;
isMoving = false;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && grounded == true)
{
isjumping = true;
}
}
void FixedUpdate()
{
if (isMoving == true)
{
Movement(speed);
limitSpeed(desiredMaxSpeed);
}
else
{
Movement(speedSlowdown );
}
if (isjumping)
{
BallJumping();
}
}
void limitSpeed(float maxSpeed)
{
if (rb.velocity.magnitude > maxSpeed)
{
rb.velocity = rb.velocity.normalized * maxSpeed;
}
}
void Movement(float currentSpeed)
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
void BallJumping()
{
rb.AddForce(Vector3.up*jumpHeight,ForceMode.VelocityChange );
isjumping = false;
}
}
Comment