I’m trying to make a game with the rolling ball from sample assets. Everytime ball goes to new plane, cube, etc it bounces. How do I make it not bounce. [31393-screen+shot+2014-08-22+at+9.59.47+pm.png|31393]
first script
`using UnityEngine;
public class Ball : MonoBehaviour
{
[SerializeField] private float movePower = 5; // The force added to the ball to move it.
[SerializeField] private bool useTorque = true; // Whether or not to use torque to move the ball.
[SerializeField] private float maxAngularVelocity = 25; // The maximum velocity the ball can rotate at.
[SerializeField] private float jumpPower = 2; // The force added to the ball when it jumps.
private const float GroundRayLength = 1f; // The length of the ray to check if the ball is grounded.
void Start()
{
// Set the maximum angular velocity.
rigidbody.maxAngularVelocity = maxAngularVelocity;
}
public void Move (Vector3 moveDirection, bool jump)
{
// If using torque to rotate the ball...
if (useTorque)
// ... add torque around the axis defined by the move direction.
rigidbody.AddTorque(new Vector3(moveDirection.z, 0, -moveDirection.x) * movePower);
else
// Otherwise add force in the move direction.
rigidbody.AddForce( moveDirection * movePower );
// If on the ground and jump is pressed...
if (Physics.Raycast(transform.position, -Vector3.up, GroundRayLength) && jump)
{
// ... add force in upwards.
rigidbody.AddForce(Vector3.up*jumpPower, ForceMode.Impulse);
}
}
}
`
end first script
begin second script
using UnityEngine;
public class BallUserControl : MonoBehaviour
{
private Ball ball; // Reference to the ball controller.
private Vector3 move; // the world-relative desired move direction, calculated from the camForward and user input.
private Transform cam; // A reference to the main camera in the scenes transform
private Vector3 camForward; // The current forward direction of the camera
bool jump; // whether the jump button is currently pressed
void Awake ()
{
// Set up the reference.
ball = GetComponent<Ball>();
// get the transform of the main camera
if (Camera.main != null)
{
cam = Camera.main.transform;
} else {
Debug.LogWarning("Warning: no main camera found. Ball needs a Camera tagged \"MainCamera\", for camera-relative controls.");
// we use world-relative controls in this case, which may not be what the user wants, but hey, we warned them!
}
}
void Update ()
{
// Get the axis and jump input.
#if CROSS_PLATFORM_INPUT
jump = CrossPlatformInput.GetButton("Jump");
float h = CrossPlatformInput.GetAxis("Horizontal");
float v = CrossPlatformInput.GetAxis("Vertical");
#else
jump = Input.GetButton("Jump");
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
#endif
// calculate move direction
if (cam != null)
{
// calculate camera relative direction to move:
camForward = Vector3.Scale (cam.forward, new Vector3(1,0,1)).normalized;
move = (v * camForward + h * cam.right).normalized;
} else {
// we use world-relative directions in the case of no main camera
move = (v * Vector3.forward + h * Vector3.right).normalized;
}
}
void FixedUpdate ()
{
// Call the Move function of the ball controller
ball.Move(move, jump);
}
}
end second script