Hello.
I want to rotate the camera around the object, but this is something that never I have been given well. I’m using “Mathf.LerpAngle”, but I think that I don’t know use this, any help or orientation, please?
Thanks.
Hello.
I want to rotate the camera around the object, but this is something that never I have been given well. I’m using “Mathf.LerpAngle”, but I think that I don’t know use this, any help or orientation, please?
Thanks.
Make the camera look at the object, then add a movement to it in Update function.
Add the below code to your camera, and set the target to the object in unity inspector window.
var target:transform;
function Update(){
transform.LookAt(target);
transform.Translate(Vector3.right * Time.deltaTime);
}
Ok, I will try, thanks!
Mortiis, Grate thanks man, this is the desired simplest code
give me a code that rotate camera left and right both sides concurently around tareget object
transform.Translate(Vector3.left * Time.deltaTime); and \transform.Translate(Vector3.right * Time.deltaTime);
you code only moves arooound left side…
i have a project on unity can i send you to give me help !!!
Well, I tried it and it came up a bug…
Applying a speed modifier to the translation I figured that when you make the object look at a target and translate it at some axis, something happens that the radius between the object and its target goes increasing along the time, and it makes the object going far from its target. Maybe UnityEngine increases the axis more than once before updating the object’s rotation.
I got better results using something like this:
using UnityEngine;
using System.Collections;
public class CameraClass : MonoBehaviour {
public TargetClass target;//the target object
private float speedMod = 10.0f;//a speed modifier
private Vector3 point;//the coord to the point where the camera looks at
void Start () {//Set up things on the start method
point = target.transform.position;//get target's coords
transform.LookAt(point);//makes the camera look to it
}
void Update () {//makes the camera rotate around "point" coords, rotating around its Y axis, 20 degrees per second times the speed modifier
transform.RotateAround (point,new Vector3(0.0f,1.0f,0.0f),20 * Time.deltaTime * speedMod);
}
}
Sorry for the code in C#, I prefer using it because it is more strong typed and Object Oriented… but it is easy to port it to javascript too… ^^
Thanks, This is what I was looking for…
I want to rotate the camera based on user touchmovement. so that I have show my 3d model in 360 degree to user how can I achieve this?
please help for me too. thanks,
Do NOT use transform.Translate(Vector3.right * Time.deltaTime);
as it will slowly move vour camera away from the object you’re rotating around.
Instead, use transform.RotateAround (object.transform.position, Vector3.up, speed * Time.deltaTime);
I’m confused by this. What is TargetClass? It doesn’t exist.
Edit: Still not sure what “TargetClass” is, but I changed “TargetClass” to “GameObject”, and found my object in the scene. Works now.
Fragmental, What he sent you is a pseudo code. TargetClass can be any MonoBehaviour attached to your GameObject, including the GameObject class! I almost always use GameObject for “target” types.
Koool buddy you saved me
hi
Make Sure you add the LookAt line after the Translate Line… for some cases it will jerk the cam.
var target:transform;
function Update(){
transform.Translate(Vector3.right * Time.deltaTime);
transform.LookAt(target);
}
[/QUOTE]
Awesome!!
please watch this video.
its short but the concept is straight forward. its the edit scene in unity where you can rotate around an object and zoom on it or what not.
How do you create this feature in in-game not in edit scene but in-game. do the above notes help?
Bump. 1st script is broken now.
New code:
using UnityEngine;
using System.Collections;
public class CameraClass : MonoBehaviour {
public GameObject target;//the target object
private float speedMod = 10.0f;//a speed modifier
private Vector3 point;//the coord to the point where the camera looks at
void Start () {//Set up things on the start method
point = target.transform.position;//get target's coords
transform.LookAt(point);//makes the camera look to it
}
void Update () {//makes the camera rotate around "point" coords, rotating around its Y axis, 20 degrees per second times the speed modifier
transform.RotateAround (target.transform.position, Vector3.up, speedMod * Time.deltaTime);
}
}
Just put the GameObject you wish to rotate around in the target slot in Inspector.
Tested working in 5.5.3f1
How would you adapt this to stop the rotation at a certain degrees, say 90 or rotate -90 using a collider the player walks or rolls into?
Try tinkering with bools = if (collidedWithThing)