Hi,im making game where i need to roll ball,i’ve already have done that,but i need to pickup/hold and throw objects when im rolling ball,im looking for a separate script.
Anyway i already tried something,but when i pickup object and roll ball the object fallows ball rotation,object is circling with the ball,through terrain and everything -wtf? Please give me script to do this.
The ball is probably the parent of your object. You should check the Hierarchy Window and make sure the two objects are not parenting one another. There’s no script to fix this - instead, please read some Unity basic tutorials.
so it is quite easy you should just do something like this:
var Player :GameObject; //your Player
var minimumDistance :float; //how near your player has to be at the ball
var PickUpPoint :Transform; //where the ball has to go after picking up (should be a child object of the player)
var hasMouseDown :boolean = false;
var isPickedUp :boolean = false;
function OnMouseOver(){
if(Vector3.Distance(transform.position, Player.transform.position) <= minimumDistance){
if(hasMouseDown){
isPickedUp = true;
}
}
}
function Update(){
if(Input.GetButtonDown("Fire1")){
hasMouseDown = true;
}/*else{
hasMouseDown = false;
}*/
if(Input.GetButtonUp("Fire1")){
hasMouseDown = false;
}
if(hasMouseDown == false){
isPickedUp = false;
}
if(isPickedUp){
this.rigidbody.useGravity = false;
transform.position = PickUpPoint.position;
}else{
this.rigidbody.useGravity = true;
}
}