尝试使其仅遵循x轴。当我用.y .y
替换时,只跟着y无论我尝试什么,它都不想工作。 (刚刚开始玩游戏开发)我在编码时非常棒。
using UnityEngine;
using System.Collections;
public class FollowCamera : MonoBehaviour
{
public float interpVelocity;
public float minDistance;
public float followDistance;
public GameObject target;
public Vector3 offset;
Vector3 targetPos;
// Use this for initialization
void Start()
{
targetPos = transform.position;
}
// Update is called once per frame
void FixedUpdate()
{
if (target)
{
Vector3 posNoZ = transform.position;
posNoZ.z = target.transform.position.z;
Vector3 targetDirection = (target.transform.position - posNoZ);
interpVelocity = targetDirection.magnitude * 5f;
Vector3 factorTowardsTarget = (targetDirection.normalized * interpVelocity * Time.deltaTime);
targetPos = new Vector3(transform.position.x, transform.position.y + factorTowardsTarget.y, transform.position.z);
transform.position = Vector3.Lerp(transform.position, targetPos + offset, 0.25f);
}
}
}
答案 0 :(得分:0)
我对自己所做的事情并不是很了解,但我试了一下。这是我的第一篇文章。
根据我的理解,他们必须有一定的顺序,X然后是Y然后是Z.而Y是将修改器添加到它的内容。我只是将修改器放在X位置上。
我测试了它,似乎有效。
我刚刚改变了这一部分:
targetPos = new Vector3(transform.position.x, transform.position.y + factorTowardsTarget.y, transform.position.z);
对此:
targetPos = new Vector3(transform.position.x + factorTowardsTarget.x, transform.position.y, transform.position.z);
结果:
using UnityEngine;
using System.Collections;
public class FollowCamera : MonoBehaviour
{
public float interpVelocity;
public float minDistance;
public float followDistance;
public GameObject target;
public Vector3 offset;
Vector3 targetPos;
// Use this for initialization
void Start()
{
targetPos = transform.position;
}
// Update is called once per frame
void FixedUpdate()
{
if (target)
{
Vector3 posNoZ = transform.position;
posNoZ.z = target.transform.position.z;
Vector3 targetDirection = (target.transform.position - posNoZ);
interpVelocity = targetDirection.magnitude * 5f;
Vector3 factorTowardsTarget = (targetDirection.normalized * interpVelocity * Time.deltaTime);
targetPos = new Vector3(transform.position.x + factorTowardsTarget.x, transform.position.y, transform.position.z);
transform.position = Vector3.Lerp(transform.position, targetPos + offset, 0.25f);
}
}
}
答案 1 :(得分:0)
此代码使相机仅在x位置跟踪对象
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wmuSlider example1 animated wow slideInUp" data-wow-delay=".5s">
<div class="wmuSliderWrapper">
<article style="position: absolute; width: 100%; opacity: 0;">
<div class="banner-wrap">
<div class="col-md-4 client-grids">
<p>In vitae tincidunt turpis. Proin in euismod dolor. Sed eget tellus venenatis, molestie lorem tempus, viverra ante vulputate.</p>
<div class="col-md-5 c-img">
<img src="images/c1.jpg" alt="" />
</div>
<div class="col-md-7 c-info">
<h4>Jackie</h4>
<h5>Businss man</h5>
</div>
<div class="clearfix"></div>
</div>
<div class="col-md-4 client-grids">
<p>In vitae tincidunt turpis. Proin in euismod dolor. Sed eget tellus venenatis, molestie lorem tempus, viverra ante vulputate.</p>
<div class="col-md-5 c-img">
<img src="images/c2.jpg" alt="" />
</div>
<div class="col-md-7 c-info">
<h4>Charlize</h4>
<h5>Teacher</h5>
</div>
<div class="clearfix"></div>
</div>
<div class="col-md-4 client-grids">
<p>In vitae tincidunt turpis. Proin in euismod dolor. Sed eget tellus venenatis, molestie lorem tempus, viverra ante vulputate.</p>
<div class="col-md-5 c-img">
<img src="images/c3.jpg" alt="" />
</div>
<div class="col-md-7 c-info">
<h4>Jessica</h4>
<h5>Engineer</h5>
</div>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
</div>
</article>
<article style="position: absolute; width: 100%; opacity: 0;">
<div class="banner-wrap">
<div class="col-md-4 client-grids">
<h3 class="midh3">my style</h3>
<p>my paragragh</p>
<div class="clearfix"></div>
</div>
<div class="col-md-4 client-grids">
<p>In vitae tincidunt turpis. Proin in euismod dolor. Sed eget tellus venenatis, molestie lorem tempus, viverra ante vulputate.</p>
<div class="col-md-5 c-img">
<img src="images/c2.jpg" alt="" />
</div>
<div class="col-md-7 c-info">
<h4>Johnson</h4>
<h5>Teacher</h5>
</div>
<div class="clearfix"></div>
</div>
<div class="col-md-4 client-grids">
<p>In vitae tincidunt turpis. Proin in euismod dolor. Sed eget tellus venenatis, molestie lorem tempus, viverra ante vulputate.</p>
<div class="col-md-5 c-img">
<img src="images/c1.jpg" alt="" />
</div>
<div class="col-md-7 c-info">
<h4>Scarllet</h4>
<h5>Businss man</h5>
</div>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
</article>
</div>
</div>
</div>
</div>
</div>
<script src="js/jquery.wmuSlider.js"></script>
<script>
$('.example1').wmuSlider();
</script>