- Home /
Everytime ball goes to new plane it bounces
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.
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
Answer by TwisterK · Aug 23, 2014 at 03:53 AM
Have you ever tried to use physical material? You can create a physical material then set bounciness to 0 then attach it to your collider so that the ball won't bounce.
Tried it. it worked ok but the ball needs to be able to bounce. There is a jump button and many heights of stuff. Its just moving from one panel or cube that are right next to eachother somehow it bounces.
Answer by archie_azares · Aug 23, 2014 at 06:23 AM
change the material attach to the ball. make it metal instead of rubber. rubber has its bouncing properties which make the ball bounce every time it lands on the ground
Tried it with metal it cant climb. it goes a little then falls down
Your answer
Follow this Question
Related Questions
How do I get a sphere to bounce of a cube at an angle 1 Answer
intelligent throwing 0 Answers
Cube bounces off wall 2 Answers
How to make a ball that can roll? 2 Answers