Sphere collider invert?

Ok so my level is based inside a sphere so I made a GameObject of a sphere made it invisible and put a sphere collider on it, but the player seems to be pushed out of the level when he comes into contact with this collider. Is it possible to invert the collider?

If the above is not possible maybe I can change gravity so that it always pushes to a point (0, 0, 0) rather than -z?

Any help is appreciated.


I solved this by using the ReverseNormals.cs script…

  • Remove your sphere collider
  • Add a mesh Collider…

Add this script to your object… call it ReverseNormals.cs (this is the same as the Wiki, I just added the line at the end to re-assign the mesh collider:
using UnityEngine;
using System.Collections;

public class ReverseNormals : MonoBehaviour {
	void Start () {
		MeshFilter filter = GetComponent(typeof (MeshFilter)) as MeshFilter;
		if (filter != null)
			Mesh mesh = filter.mesh;
			Vector3[] normals = mesh.normals;
			for (int i=0;i<normals.Length;i++)
				normals _= -normals*;*_

* mesh.normals = normals;*

* for (int m=0;m<mesh.subMeshCount;m++)*
* {*
* int[] triangles = mesh.GetTriangles(m);*
* for (int i=0;i<triangles.Length;i+=3)*
* {*
* int temp = triangles[i + 0];*
* triangles[i + 0] = triangles[i + 1];*
* triangles[i + 1] = temp;*
* }*
* mesh.SetTriangles(triangles, m);*
* }*
* } *

* this.GetComponent().sharedMesh = filter.mesh;*
* }*

Take a look at Vector3.Reflect

50f is the radius of sphere.
myCenterPosition is center position of sphere (Vector3).
dumping is simply decreases velocity 75%
Script adds random velocity to object on each collision. Use in FixedUpdate

if(Vector3.Distance(myCenterPosition,  transform.position) > 50f)
    float dumping = 0.75f;
	rigidbody.velocity = Vector3.Reflect(rigidbody.velocity * dumping, (myCenterPosition - transform.position).normalized);
	Vector3 f = new Vector3(Random.value, Random.value, Random.value) * 20;
	rigidbody.AddForce( f);

At first, try this …

it will simply bounce it back towards the center each time…

float d = Vector3.Distance(
   myCenterPosition, transform.position);
if( d > 50f )
Vector3 directionToCenter =
   (myCenterPosition - transform.position).normalized;
Vector3 f = directionToCenter * 25f; // try different values

regarding “Data addition via accelerometer”. Start new question.

Regarding “Golf ball is moving automatically because above code is running and I want to stop this”

  1. i already said, change the factor “20” to various different factor, perhaps 0.1 or 0.001 or 100 or 1. TAKES A LOT OF YOUR TIME TO EXPERIMENT

  2. I already said, try my alternate approach, SEE CODE IN THE ANSWER HERE, “lower” code section

  3. I already gave you suggestion about water, that is valuable tip. try it.

  4. Experiment with things like “drag” on rigidbody

however note

  1. Siddh. to make physics on video game TAKES A LOT OF EXPERIMENTATION – THERE IS NO “OFFICIAL” ANSWER. YOU OFTEN HAVE TO EXPERIMENT FOR WEEKS to “Tune” system to get “video game look” you want. is “up to you”

if you have VERY SPECIFIC question, for example, “I want it to float upwards” or “it does not bounce fast enough” or “it does not bounce slow enough” or whatever, you must ask tht specifiv question.

ask as NEW question, include video and current code in question

The answer will depend on what you’re trying to achieve.

I believe you want the player to be inside some kind of bubble, and to walk on it’s faces or something like that. Unfortunately, that’s not how Sphere collider work, it’s a very basic computation based on distance (or so I think). You need a sphere mesh with it’s faces turned inwards, with a mesh collider (but no renderer if you don’t want to see it).

On the other hand, if you want the sphere to act like a boundary in your scene, you need it to be a trigger.