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?
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;
[RequireComponent(typeof(MeshFilter))]
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*;*_
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
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”
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
I already said, try my alternate approach, SEE CODE IN THE ANSWER HERE, “lower” code section
I already gave you suggestion about water, that is valuable tip. try it.
Experiment with things like “drag” on rigidbody
however note
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.