求助大神,请问这块板在LOOK到180度时不翻转??谢谢啊!
unity3d吧
全部回复
仅看楼主
level 5
killmmmm 楼主
请问大神,途中这块大盒子要一直LOOK
小方块
,但是转到180度时就会翻转,请问怎么让大盒子不翻转,保持轴向??感谢感谢。
using UnityEngine;
public class HH_look : MonoBehaviour
{
public Transform target;
public Transform player;
Vector3 relativePos;
Quaternion StartRotation;
void Awake()
{
relativePos = target.position - player.position;
StartRotation = player.transform.rotation;
}
void LateUpdate()
{
player.rotation = Quaternion.FromToRotation(relativePos, target.position - player.position) * StartRotation;
//relativePos.y = 0;//player物体朝向target物体时默认y轴会有倾斜,如果不想倾斜,可设置y轴坐标为0
}
}
2021年05月11日 13点05分 1
level 8
y=0放update里,有刚体的话。可以固定轴,禁止轴旋转
2021年05月11日 13点05分 2
大神,我刚才试了,吧Y=0放在了UPDATE里,还是一样,要到180度的时候开始翻转。转了几圈。但是这个物体不能是刚体。因为是一个子物体。请问还有方法不让它翻转吗?下面发个截图。谢谢大神。
2021年05月11日 14点05分
@killmmmm 你是要实现什么功能?子物体绕父物体自转?哪条轴要转就设值,哪条不让转就设0
2021年05月11日 14点05分
@界外回旋 不是,是这个大盒子始终面向这个小盒子。但要保持轴向不变,刚才抄了一个这个方法。但是这个方法是慢慢转过去的,但是就不会胡乱翻转了,player.rotation = Quaternion.Slerp(player.rotation, Quaternion.LookRotation(target.position - player.position),10 * Time.deltaTime);
2021年05月11日 14点05分
@界外回旋 怎么让它即时面向,而不是慢慢转过去[汗]
2021年05月11日 14点05分
level 5
killmmmm 楼主
2021年05月11日 14点05分 3
level 8
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour
{
public Transform target;
public Transform player;
void Update()
{
player.RotateAround(target.position, Vector3.up, 30 * Time.deltaTime);
}
}
这样?
2021年05月11日 15点05分 5
不是围绕,是始终面向一个点,[乖]
2021年05月11日 15点05分
回复killmmmm:面向一个点,哪个点?小方块?,做什么运动,你说清楚啊[汗]
2021年05月11日 15点05分
@界外回旋 下面跟帖的这个角色想控制一个骨骼一直面向一个点,正面还正常,转180度到后面就这样了。看图,[滑稽]
2021年05月11日 16点05分
@界外回旋 图片上传失败。哎。。
2021年05月11日 16点05分
1