- Home /
Gravity Modification And Camera Rotation Issue
Hi all,
I'm using Unity's built-in gravitational system and rigidbodies etc and I'm wishing to have a gravity modifier that the player picks up and can then have the wall behave as the current floor.
I've done most of it, I can get the player to stick to the wall no problems, but I need the camera to rotate so that it's downwards direction is negative to gravity.
I've been trying for weeks to get this but I get close and then another problem arises.
So this is what I have at the moment, I've tried so many other methods but this is the current one:
On the player script:
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Gravity")
{
Physics.gravity = new Vector3(98.1f, 0, 0);
other.gameObject.SetActive(false);
//cameraContainer.position = -Physics.gravity;
//playerGravity.Rotate(Vector3.forward, 270);
//mainCamera.Rotate (Vector3.forward, 120);
//mainCamera.Rotate(Vector3.up, 25);
//GameObject.FindGameObjectWithTag("MainCamera");
//Camera.main.transform.Rotate(90, 0, 0);
}
}
On the cameraContainer (this is a parent of the Main Camera):
void Update()
{
if (Physics.gravity = Vector3(98.1f, 0, 0))
{
transform.Rotate (Vector3.right, 90);
}
transform.position = target.position;
//transform.up = -Physics.gravity;
}
As you can see I've tried making the cameraContainer's transform.up equal to negative to gravity but that messes up the angle I have the camera set to (I need it facing the player at an x rotation of 33 and a y rotation of 45 and keep the same look once the gravity has taken over.
Now the "if (Physics.gravity)" thing isn't working, I'm clearly missing something or doing that wrong, so that may be all I need to work out, but I posted all this in case one of you brilliant people out there know how to do this correctly.
Thanks, really need some help!
Answer by jonofarc · Nov 11, 2015 at 06:04 AM
With the code you posted in here.
if (Physics.gravity = Vector3(98.1f, 0, 0))
You are missing double equal it should be
if (Physics.gravity == Vector3(98.1f, 0, 0))
Otherwise you are making a statement and not a comparison
See if that helps
Thanks for the help, didn't realize that, but it's given me this error now:
Assets/Scripts/CameraContain.cs(21,32): error CS0119: Expression denotes a type', where a
variable', value' or
method group' was expected
I have no idea what it wants out of me this time, lmao.
Okay so apparently I needed the 'new' infront of the Vector3 value. But I'm trying to find out a value that already exists in the other script and it's based off of Unity's built-in physics.
So I tried it and it didn't actually read that gravity had changed on collision, there-for it did nothing for the camera rotation.
Do you perhaps know how I might achieve this correctly?