- Home /
Unity3D HELP! How can i pickup/hold/throw object when im rolling ball?
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.
Player is the Ball,remember that.
in your title " im " needs an apostrophe, like this ..
I'm
would you be able to click "edit" and change it? Thanks!
O$$anonymous$$, I waited a $$anonymous$$ute, RIGHT NEXT TO where you clicked "Comment", if you just click "edit", you can then edit your headline! Then just click save.
See where you typed "Please give me script to do this." ...
look just UNDER that and to the LEFT you will see the edit button.
you can then click edit and fix the apostrophe in your headline.
Player is the ball that script is not working,which is underground not working.
Answer by ivomarel · Jun 20, 2012 at 11:26 AM
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.
thats not problem,i just need script to do what i wrote here.
Answer by bubblegumsoldier · Jun 20, 2012 at 11:50 AM
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;
}
}
Answer by bubblegumsoldier · Jun 20, 2012 at 12:19 PM
so you should grad this script on the PickUpPoint (!!!It may not be a child object of the player!!!): var Player :Transform;
var distance_x :float;
var distance_y :float;
var distance_z :float;
function Update (){
transform.position.x = Player.position.x + distance_x;
transform.position.y = Player.position.y + distance_y;
transform.position.z = Player.position.z + distance_z;
transform.rotation.x = Player.rotation.x;
transform.rotation.y = Player.rotation.y;
}