- Home /
How to make planet walker camera ?
like this camera
Answer by robertbu · Aug 05, 2013 at 01:55 AM
If you are talking about the movement of the block on the mesh, try the script by me that is in the last comment in this question:
http://answers.unity3d.com/questions/485986/face-to-direction-in-a-mario-galaxy-style-game.html
As for the camera movement, it looks like a standard SmoothFollow script. If you do Assets > Import Package > Scripts, you will get this script.
I'm not talking about the Box who walks above the planet's surface I am interested in the camera that follows Box on the surface of the planet is a regular Such as what is in the video clip
http://www.youtube.com/watch?v=20XOYor$$anonymous$$Wts
and this is my code for the camera
using UnityEngine;
using System.Collections;
public class mycamera : $$anonymous$$onoBehaviour {
Vector3 backv;
Vector3 upv;
Quaternion fromtoRotation;
public Transform target;
// Use this for initialization
void FixedUpdate () {
backv = -target.forward*10f;
upv = target.up*10f;
}
// Update is called once per frame
void LateUpdate () {
fromtoRotation = transform.rotation * Quaternion.FromToRotation(transform.up, Vector3.up);
transform.rotation = Quaternion.Lerp(transform.rotation,fromtoRotation,Time.deltaTime * .1f);
transform.position = target.position + (backv + upv);
transform.LookAt(target,Vector3.up);
}
}
I think the problem here:
void FixedUpdate () { backv = -target.forward*10f; upv = target.up*10f;
}
or here:
transform.position = target.position + (backv + upv);
The problem is that the orientation of the camera is changing dramatically, because it is tied with the movement of the goal that moves on the surface of curvy planet .
Another problem that the camera sometimes flapped its direction
this is my problem in video:
http://www.youtube.com/watch?v=vgVUIboFe$$anonymous$$k
Try this script. It positions the camera with respect to the object's up and back regardless of the rotation.
using UnityEngine;
using System.Collections;
public class SmoothFollow3D : $$anonymous$$onoBehaviour {
public Transform target;
public float upDistance = 7.0f;
public float backDistance = 10.0f;
public float trackingSpeed = 3.0f;
public float rotationSpeed = 9.0f;
private Vector3 v3To;
private Quaternion qTo;
void LateUpdate () {
v3To = target.position - target.forward * backDistance + target.up * upDistance;
transform.position = Vector3.Lerp (transform.position, v3To, trackingSpeed * Time.deltaTime);
qTo = Quaternion.LookRotation(target.position - transform.position, target.up);
transform.rotation = Quaternion.Slerp (transform.rotation, qTo, rotationSpeed * Time.deltaTime);
}
}
thanks for this code is useful
using UnityEngine;
using System.Collections;
public class SmoothFollow3D : $$anonymous$$onoBehaviour {
public Transform target;
public float upDistance = 7.0f;
public float backDistance = 10.0f;
public float trackingSpeed = 3.0f;
public float rotationSpeed = 9.0f;
private Vector3 v3To;
private Quaternion qTo;
void LateUpdate () {
v3To = target.position - target.forward * backDistance + target.up * upDistance;
transform.position = Vector3.Lerp (transform.position, v3To, trackingSpeed * Time.deltaTime);
qTo = Quaternion.LookRotation(target.position - transform.position, target.up);
transform.rotation = Quaternion.Slerp (transform.rotation, qTo, rotationSpeed * Time.deltaTime);
}
}
i liked the way how the camera is Following target , but its not Smooth ,because the camera take directly his position and rotation from position and rotation of target .
So the camera move its rapidly with the new target location This rapid movement create instability in the movement of the camera
I hope that you look at the may video to see what I mean:
http://www.youtube.com/watch?v=OLPCzS3ao2I
look for this camera its perfect
how i can make like this camera http://www.youtube.com/watch?v=20XOYor$$anonymous$$Wts
plez helpe
Did you try playing with the trackingSpeed and rotationSpeed parameters I put in the script? Another think you can try is to change Vector3.Lerp() to Vector3.$$anonymous$$oveTowards(), and Quaternion.Slerp() to Quaternion.RotateTowards(). The parameters/format will be the same, but the appropriate value for trackingSpeed and rotationSpeed will be very different. If you are still having problems, you might have to give me a simple package to play with. Sometimes I just have to play with different ideas until I get something that fits.
this is the solution but i don't understand how i can make it?
well that's easy: just use two different GameObjects, one empty gameobject for the thing you're already doing (sticking on the surface, orienting on the surface) and another GameObject with the real graphics of your character/vehicle. The latter one can quaternion.slerp to the desired rotation thus making the movement/rotation smooth and not jumpy
plez help
Answer by robhuhn · Aug 05, 2013 at 06:56 AM
In the comments section of this video the creator visioneleven says:
did the gravity with these single line of code: object.rigidbody.velocity += (centerax.transform.position - object.transform.position).normalized 10 Time.deltaTime;The script is very simple. I just rotate the whole world with key arrows. All the yellow enemys are rigidbodys with gravity disabled. I
Centerax is the center of the planet...
Also this skript could help for a body-to-body gravity: http://wiki.unity3d.com/index.php?title=Gravity
thanks for this code is useful
using UnityEngine;
using System.Collections;
public class SmoothFollow3D : $$anonymous$$onoBehaviour {
public Transform target;
public float upDistance = 7.0f;
public float backDistance = 10.0f;
public float trackingSpeed = 3.0f;
public float rotationSpeed = 9.0f;
private Vector3 v3To;
private Quaternion qTo;
void LateUpdate () {
v3To = target.position - target.forward * backDistance + target.up * upDistance;
transform.position = Vector3.Lerp (transform.position, v3To, trackingSpeed * Time.deltaTime);
qTo = Quaternion.LookRotation(target.position - transform.position, target.up);
transform.rotation = Quaternion.Slerp (transform.rotation, qTo, rotationSpeed * Time.deltaTime);
}
}
i liked the way how the camera is Following target , but its not Smooth ,because the camera take directly his position and rotation from position and rotation of target .
So the camera move its rapidly with the new target location This rapid movement create instability in the movement of the camera
I hope that you look at the may video to see what I mean:
http://www.youtube.com/watch?v=OLPCzS3ao2I
look for this camera its perfect
how i can make like this camera http://www.youtube.com/watch?v=20XOYor$$anonymous$$Wts
plez helpe
Answer by aldonaletto · Aug 05, 2013 at 01:59 AM
You could try the script posted in the question Walking On Walls - it uses a rigidbody character that can walk over any surface, even upside down.
I'm not talking about the Box who walks above the planet's surface I am interested in the camera that follows Box on the surface of the planet is a regular Such as what is in the video clip
http://www.youtube.com/watch?v=20XOYor$$anonymous$$Wts
and this is my code for the camera
using UnityEngine;
using System.Collections;
public class mycamera : $$anonymous$$onoBehaviour {
Vector3 backv;
Vector3 upv;
Quaternion fromtoRotation;
public Transform target;
// Use this for initialization
void FixedUpdate () {
backv = -target.forward*10f;
upv = target.up*10f;
}
// Update is called once per frame
void LateUpdate () {
fromtoRotation = transform.rotation * Quaternion.FromToRotation(transform.up, Vector3.up);
transform.rotation = Quaternion.Lerp(transform.rotation,fromtoRotation,Time.deltaTime * .1f);
transform.position = target.position + (backv + upv);
transform.LookAt(target,Vector3.up);
}
}
I think the problem here:
void FixedUpdate () { backv = -target.forward*10f; upv = target.up*10f;
}
or here:
transform.position = target.position + (backv + upv);
The problem is that the orientation of the camera is changing dramatically, because it is tied with the movement of the goal that moves on the surface of curvy planet .
Another problem that the camera sometimes flapped its direction
this is my problem in video:
http://www.youtube.com/watch?v=vgVUIboFe$$anonymous$$k
thanks for this code is useful
using UnityEngine;
using System.Collections;
public class SmoothFollow3D : $$anonymous$$onoBehaviour {
public Transform target;
public float upDistance = 7.0f;
public float backDistance = 10.0f;
public float trackingSpeed = 3.0f;
public float rotationSpeed = 9.0f;
private Vector3 v3To;
private Quaternion qTo;
void LateUpdate () {
v3To = target.position - target.forward * backDistance + target.up * upDistance;
transform.position = Vector3.Lerp (transform.position, v3To, trackingSpeed * Time.deltaTime);
qTo = Quaternion.LookRotation(target.position - transform.position, target.up);
transform.rotation = Quaternion.Slerp (transform.rotation, qTo, rotationSpeed * Time.deltaTime);
}
}
i liked the way how the camera is Following target , but its not Smooth ,because the camera take directly his position and rotation from position and rotation of target .
So the camera move its rapidly with the new target location This rapid movement create instability in the movement of the camera
I hope that you look at the may video to see what I mean:
http://www.youtube.com/watch?v=OLPCzS3ao2I
look for this camera its perfect
how i can make like this camera http://www.youtube.com/watch?v=20XOYor$$anonymous$$Wts
plez helpe
Answer by malikcgcs · Aug 25, 2013 at 02:30 PM
using UnityEngine;
using System.Collections;
public class mooove : MonoBehaviour {
public float moveSpeed = 0.1f;
public float turnSmoothing = 15f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
float h = Input.GetAxis("Horizontal")* moveSpeed * Time.deltaTime;
//transform.position += transform.right * h;
float v = Input.GetAxis("Vertical")* moveSpeed * Time.deltaTime;
//transform.position += transform.forward * v;
MovementManagement(h,v);
if(h != 0f || v != 0f)
{
transform.position += transform.right * .05f;
}
}
void MovementManagement (float horizontal, float vertical)
{
// If there is some axis input...
if(horizontal != 0f || vertical != 0f)
{
// ... set the players rotation and set the speed parameter to 5.5f.
Rotating(horizontal, vertical);
//Vector3 targetDirection1 = new Vector3(horizontal, 0f, vertical);
}
}
void Rotating (float horizontal, float vertical)
{
// Create a new vector of the horizontal and vertical inputs.
Vector3 targetDirection = new Vector3(horizontal, 0f, vertical);
//transform.position += transform.TransformDirection(targetDirection);
// Create a rotation based on this new vector assuming that up is the global y axis.
Quaternion targetRotation = Quaternion.LookRotation(targetDirection, Vector3.up);
// Create a rotation that is an increment closer to the target rotation from the player's rotation.
Quaternion newRotation = Quaternion.Lerp(rigidbody.rotation, targetRotation, turnSmoothing * Time.deltaTime);
// Change the players rotation to this new rotation.
rigidbody.MoveRotation(newRotation);
}
}
Line 21 you are checking for an input, and also at line 32. Why not just call the function in the conditional after line 21?
I'm really not sure why you posted this answer without any explanation.
i have Rotating function:
void Rotating (float horizontal, float vertical)
{
transform.position += transform.forward * .007f;
RaycastHit hit;
if (Physics.Raycast (transform.position , -transform.up, out hit, $$anonymous$$athf.Infinity)) {
// Stick on surface
transform.position = hit.point + (transform.up * desGro);
// Create a new vector of the horizontal and vertical inputs.
Vector3 targetDirection = new Vector3(horizontal, 0f, vertical);
// Create a rotation based on this new vector assu$$anonymous$$g that up is the global y axis.
Quaternion targetRotation = Quaternion.LookRotation(targetDirection,transform.up);
// Create a rotation that is an increment closer to the target rotation from the player's rotation.
// Change the players rotation to this new rotation.
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, rota * Time.deltaTime);
Quaternion fro = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
transform.rotation = Quaternion.RotateTowards(transform.rotation, fro, Time.deltaTime * 2000f);
}
}
The problem is that Walker does not modify the his Quaternion (transform.rotation ) to be Stick on the surface.
this is video about my problem:
[http://www.youtube.com/watch?v=ZCxOTZtGxY$$anonymous$$][1]
plez help
[1]: http://www.youtube.com/watch?v=ZCxOTZtGxY$$anonymous$$
i think the targetDirection Vector3 targetDirection = new Vector3(horizontal, 0f, vertical);
most be calculated in another way , I think we must take into account the (hit.normal) If we have introduced the (hit.normal) with the target Direction,
one way or another
Then can combine:
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, rota * Time.deltaTime);
Quaternion fro = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
transform.rotation = Quaternion.RotateTowards(transform.rotation, fro, Time.deltaTime * 2000f);
to one method:
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, rota * Time.deltaTime);
/*In the quaternion world, multiplication is the way to apply the rotation to something - when you multiple quaternion by vector3. you're actually rotating the vector./
like this? plez help
Vector3 targetDirection = new Vector3(horizontal, 0f, vertical);
Quaternion fro = Quaternion.FromToRotation(transform.up,hit.normal) * transform.rotation;
targetDirection = fro *targetDirection ;
Your answer
![](https://koobas.hobune.stream/wayback/20220613111540im_/https://answers.unity.com/themes/thub/images/avi.jpg)