- Home /
find a sphere position
hi I am new at unity and i want to ask a questions. I am stuck last two days to make this. I have sphere and i want to bounce it as a ball but i cant understood that how i will take it specific location. I mean when i press it left bottom the sphere will bounce to the right with touching angle and when i touch right bottom it will bounce to the left same. I am taking position but it is not sphere position it is global positon. Here is my code. Sorry for my English :)
private var hit : RaycastHit; private var ray : Ray; var skor : int=0; private var speed : float = 0.1;
function Update () {
for(var touch : Touch in Input.touches)
{
if(Input.GetTouch(0).phase==TouchPhase.Began) {
ray = Camera.main.ScreenPointToRay(Input.touches[0].position);
Debug.DrawLine(ray.origin,ray.direction * 10);
if(Physics.Raycast(ray.origin, ray.direction * 10,hit)){
if(hit.collider.gameObject.name=="top")
{
if(!gameObject.rigidbody)
{
gameObject.AddComponent(Rigidbody);
rigidbody.mass=0.1;
}
var pozisyon : float = Input.touches[0].position.x;
var ekranOrta : Vector3 = new Vector3( Screen.width/2,Screen.height/2,0);
var dokunmaPozisyon : Vector3 = Input.touches[0].position - ekranOrta;
var UpVektor : Vector3 = new Vector3(0,1,0);
var aci : float = Vector3.Angle(UpVektor, dokunmaPozisyon);
if(Input.GetTouch(0).position.x>425)
rigidbody.AddForce(Vector3(-aci*speed,40,0));
else if(Input.GetTouch(0).position.x<425)
rigidbody.AddForce(Vector3(aci*speed,40,0));
else if(Input.GetTouch(0).position.x==425)
rigidbody.AddForce(Vector3(0,40,0));
skor++;
var skorYazi : GUIText = gameObject.Find("skor").GetComponent(GUIText);
skorYazi.text=""+skor;
}
}
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613073527im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Sphere "skids" on turns without rotating 1 Answer
I wanna setup something like Kinematic option on sphere but with collision checker. 0 Answers
how to control the horizontal position of object in a 4 units wide plane? 0 Answers
Camera rotation around player while following. 6 Answers
Position waypoint along sphere 1 Answer