- Home /
Bounce with speed
hey i write a bounce code
`#pragma strict
private var DirectionX:int;
private var YFactor:float;
private var XFactor:float;
function Start ()
{
YFactor = 9;
XFactor = 0.6f * DirectionX; //DirectionX =-1/1
}
function FixedUpdate()
{
}
function Update ()
{
}
function OnCollisionEnter(collisionInfo:Collision)
{
if(collisionInfo.transform.tag == "Base")
{
this.rigidbody.AddForce(Vector3.up*YFactor,ForceMode.Impulse);
this.rigidbody.AddForce(Vector3.right*XFactor,ForceMode.VelocityChange);
}
else if(collisionInfo.transform.tag == "Wall")
{
XFactor *= -1;
this.rigidbody.AddForce(Vector3.right*XFactor*2,ForceMode.VelocityChange);
}
}` now if i attach this script to an object that will start bounce(without bounce material) but with a constant speed. so my question is if i need that one ball bounce faster than the other one i have to set a speed for it but don't understand where,changing in "YFactor" will only increase its height of bounce .plz any solution .
suggest unityGE$$anonymous$$S.com for basic tutorials
the physics engine in Unity will do all the bouncing for you. you do nothing.
Answer by nullkraft · Oct 29, 2012 at 02:00 AM
You need to set an initial velocity. It's not pretty but it works.
This gives you a control that will let you set the x, y and z components. For example, to set the initial velocity for gravity you would set the y component to -10. Most other velocities would be set with a positive value in the proper direction.
public var initialVelocity : Vector3;
function Start() {
transform.ridigbody.velocity = initialVelocity;
}
Thanks for reply but its not working,is there anyway that I can change the time scale for particular one object in scene.
yes, it's very simple. just use the CONSTANT FORCE component.
one click. find "constant force" in the menu of Unity
never, ever change gravity for any reason
just go to unityGE$$anonymous$$S.com for a full intro
Your answer
Follow this Question
Related Questions
How do you keep a bouncing ball from "breaking" through cloth 1 Answer
Help me bounce (make player bounce when landing from a jump) 0 Answers
pong question 2 Answers
Vector3.Reflect - object bounce 1 Answer
How to reduce bounce? 1 Answer