How to exclude Player from Picking himself up! C#

Hello,

I am trying to pick up objects only in my viewfrustrum, not occluded from my view and exclude the player, WHICH IS in my view ugh…
Because its a third person camera. So I am thinking that is the issue. I can only pick up objects when i comment out the line “if (obj.name == “Player”) return false;” BUT THE PLAYER IS PICKED UP TOO! I DONT want that to happen…

“ObjectInteractable” simply excludes objects that do not meet the criteria for being able to be moved by the controller… Thanks!

// returns condition for if force should affect this object.
	bool ObjectInteractable(GameObject obj) {
		if (obj.rigidbody == null) return false;
		if (obj.name == "Player") return false;
		
		// ignore objects not in the view frustum.
		if (GeometryUtility.TestPlanesAABB(GeometryUtility.CalculateFrustumPlanes(Camera.main), obj.collider.bounds) == false) {
			return false;
		}
		
		// ignore objects that are occluded from our view.
		RaycastHit hit;
		if(Physics.Linecast(transform.position, obj.transform.position, out hit)) {
			if (hit.transform != obj.transform) return false;	
		}
		
		return true;
	}
	
	void Levetate() {
		if (Time.time - m_lastPushTime < 1.0f) return;
		StageOneLevetate();
	}
	
	void StageOneLevetate() {
		Collider [] m_pullObjects = Physics.OverlapSphere(transform.position, 10.0f);
		for(int i = 0; i < m_pullObjects.Length; ++i) {
			GameObject gObject = m_pullObjects*.transform.gameObject;*
  •  	if (ObjectInteractable(gObject) == false) continue;*
    
  •  	if (gObject.rigidbody.mass < 1.0f) {*
    

gObject.rigidbody.velocity = Vector3.up * Random.Range(0.5f, 0.8f) * (1.0f + (m_forcePoints / 500.0f));

  •  		gObject.rigidbody.AddTorque(new Vector3(Random.Range(-0.02f, 0.02f), Random.Range(-0.02f, 0.02f), Random.Range(-0.02f, 0.02f)));	*
    
  •  	}*
    
  •  	else if (gObject.rigidbody.mass < 5.0f) {*
    

gObject.rigidbody.velocity = Vector3.up * Random.Range(0.3f, 0.4f) * (1.0f + (m_forcePoints / 500.0f));

  •  		gObject.rigidbody.AddTorque(new Vector3(Random.Range(-0.01f, 0.01f), Random.Range(-0.01f, 0.01f), Random.Range(-0.01f, 0.01f)));*
    
  •  	}*
    
  •  }*
    
  • }*
    Thanks for the help!

Scripts for interactable objects

Generally I would have a separate script attached to the interactable objects. For instance:

foreach (var collider in Physics.OverlapSphere(transform.position, 10.0f)) {
    var interactable = collider.GetComponent<InteractableObject>();
    if (interactable == null)
        continue;

    interactable.Interact(m_forcePoints);
}

Eliminate objects within character hierarchy

Or, to eliminate objects within the hierarchy of your character you could using something like the following:

public bool IsPlayerObject(Transform t) {
    var playerTransform = transform;
    while (t != null) {
        if (t == playerTransform)
            return true;
        t = t.parent;
    }
    return false;
}

And then:

if (IsPlayerObject(m_pullObjects*.transform))*

continue;
Other than that, I am really unsure as to how I can help…