Hey guys just wondering as the title says. I am trying to make a mario galaxy kind of mechanic where I am attracted towards a planet that I raycast. I am stuck, if you can give me a little bit of help here I would appreaceate it!
GameObject attractedTo;
public float strengthOfAttraction = 10.0f;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast (ray, out hit)){
Debug.Log(hit.point);
attractedTo = new Vector3(hit);
Vector3 direction = attractedTo.transform.position - transform.position;
Vector3 planetDirection = strengthOfAttraction * direction;
rigidbody.AddForce((planetDirection - transform.position).normalized);
}
↧