Comments and answers for "How do I translate around a circle?"
http://answers.unity.com/questions/414930/how-do-i-translate-around-a-circle.html
The latest comments and answers for the question "How do I translate around a circle?"Comment by Owen-Reynolds on Owen-Reynolds's answer
http://answers.unity.com/comments/415675/view.html
That's a known, fragile hack. Rigidbodies are meant to move by setting their speed (various ways) and allowing the physics steps to move them.
BUT, any method that moves them 1) not-too-much, 2) from their current position (like your lerp, but Translate and many other ways) will sort of work on any collider+RB. As long as they never overlap too much, the physics step will pop them apart (the same way that overlapping cubes will when you press Play.)Tue, 12 Mar 2013 21:02:09 GMTOwen-ReynoldsAnswer by SikoraP13
http://answers.unity.com/answers/415115/view.html
I managed to solve the problem. I remade the code entirely using a Lerp function to modify the position if the old position was not the same as the new position and realized that making the camera position a camera rigidbody position change would prevent it from colliding with the terrain. I then turned on extrapolate in the rigidbody menu on the unity inspector. The code is included for anyone who's looking for it. This allows for both zoom and panning around the center point.
Thanks to everyone who tried to help out!
if (camType==1){
float length = Mathf.Cos(centerAng.y*0.0174532925f)*centerDist;
if ((isLeftKeyDown)&&(isMove=true)){
centerAng.x -= centRotSens;
// Avoid rotation below 0 degrees
while (centerAng.x < 0) {
centerAng.x = 360.0f - Mathf.Abs(centerAng.x);
}
}
if ((isRightKeyDown)&&(isMove=true)) {
centerAng.x += centRotSens;
// Avoid rotation above 360 degrees
while (centerAng.x > 360) {
centerAng.x = 0.0f + (Mathf.Abs(centerAng.x) - 360.0f);
}
}
if ((isUpKeyDown)&&(isMove=true)) {
centerAng.y += centPitSens;
// Avoid pitch above 90 degrees
if (centerAng.y > 90) {
centerAng.y = 90.0f;
}
}
if ((isDownKeyDown)&&(isMove=true)) {
centerAng.y -= centPitSens;
// Avoid pitch below 0 degrees
if (centerAng.y < 0) {
centerAng.y = 0.0f;
}
}
// Control zoom
if (Input.GetAxis("Mouse ScrollWheel")<0) {
centerDist += 20.0f;
if (centerDist > 2000) {
centerDist = 2000.0f;
}
}
if (Input.GetAxis("Mouse ScrollWheel")>0) {
centerDist -= 20.0f;
if (centerDist < 100) {
centerDist = 100.0f;
}
}
if (mouse1IsDown) {
// Listen for mouse x/y, change x/z center position depending on rotation angle
float transX = Input.GetAxis("Mouse X")*15.0f;
float transZ = Input.GetAxis("Mouse Y")*15.0f;
centerPos.x += Mathf.Sin(centerAng.x*0.0174532925f)*transX + Mathf.Cos(centerAng.x*0.0174532925f)*transZ;
centerPos.z += -Mathf.Cos(centerAng.x*0.0174532925f)*transX + Mathf.Sin(centerAng.x*0.0174532925f)*transZ;
}
// Convert centerPos, centerAng, centerDist to Camera position
float posX = centerPos.x+ Mathf.Cos(centerAng.x*0.0174532925f)*length;
float posZ = centerPos.z+ Mathf.Sin(centerAng.x*0.0174532925f)*length;
float posY = Mathf.Sin(centerAng.y*0.0174532925f)*centerDist+centerPos.y;
//Change Camera to a rigid body
Camera.main.transform.rigidbody.position=Vector3.Lerp(Camera.main.transform.position, new Vector3(posX,posY,posZ),60*Time.deltaTime);
Camera.main.transform.LookAt(centerPos);
}Mon, 11 Mar 2013 23:39:00 GMTSikoraP13Comment by SikoraP13 on SikoraP13's answer
http://answers.unity.com/comments/415050/view.html
That's the issue, yes. We've got a terrain generated. The camera needs to focus on and stay looking at a center point and be able to rotate 360 degrees around that point (X-Z plane) and up from 0 to 90 degrees on the Y axis. Currently the Y axis collision seems to work, but the X-Z plane collision doesn't work with the old transform code, essentially allowing the camera to fly through the side of a mountain.Mon, 11 Mar 2013 21:28:05 GMTSikoraP13Comment by Owen-Reynolds on Owen-Reynolds's answer
http://answers.unity.com/comments/415038/view.html
`Translate` and `position=` each go through solid objects, but will trigger OnCollision (but not if you teleport deep under a hill.)
But, to avoid an underground camera (is that the issue?) might be easier to look up the ground height.Mon, 11 Mar 2013 21:17:38 GMTOwen-ReynoldsComment by SikoraP13 on SikoraP13's answer
http://answers.unity.com/comments/415034/view.html
We had it working with a transform position, but with the way that the code is set up for the terrain collider, which uses OnCollision, the transform function allows it to go through the world. Here's the code for the collider that we're currently using. So essentially, it only works when there's an actual collision. For there to be a collision, to my understanding, it needs to be a Translate not a transform. I don't know enough about how Quaternions work, but any help on that would be appreciated.
void OnCollision(Collision collisionInfo) {
Debug.Log("Collision Detected");
Camera.main.transform.Translate(collisionInfo.contacts[0].normal*5.0f);
}Mon, 11 Mar 2013 21:09:42 GMTSikoraP13Answer by Owen-Reynolds
http://answers.unity.com/answers/415008/view.html
If this is non-standard enough that it can't be a predone orbit script...:
Translate is just a conveniance function to apply a local motion. It looks like you know exactly where you want to be (aimed at centerPos, offset by dX, dY and dZ based on the angles?) In that case, you can just put the camera there directly: `Camera.main.transform.position = new Vector(centerPos.x+dx, ...);`.
The cos/sins could be replaced by a Quaternion times a vector, which does the math for you. All of the dx/y/z stuff would become something like: `Vector3 fromCenter = Quaternion.Euler(xSpin, ySpin, 0)*Vector3.forwards;`
Then, so I don't lose my license, consider using `Mathf.Deg2Rad` instead of 0.017, or at least `const float C1 = 0.017;`Mon, 11 Mar 2013 20:40:55 GMTOwen-ReynoldsAnswer by DaveA
http://answers.unity.com/answers/414933/view.html
Assets/Import package/Scripts Find Standard Assets/Camera Scripts/MouseOrbit. Drop that on your camera. Drop the target object on the target of that script.Mon, 11 Mar 2013 18:46:54 GMTDaveA