所以我正努力让我的移动平台对我的播放器稳定。
我使用了void OnCollisionEnter2D(Collision2D other)
'在平台容器内部脚本中使用' player.transform.SetParent(plankTranform);
'
但是设置玩家变换为平台变换的孩子会与玩家的规模混淆。
我最好的猜测是平台的比例属性正在转移到玩家的transform.scale中。是否可以将tranform.position
平台设置为播放器transform.position
的父级?
使用player.transform.SetParent(plankTranform);
自动将转换3属性(即位置,比例,旋转)设置为子对象。在这种情况下,我真的很想处理比例和旋转
public class BrickMoveVErtical : MonoBehaviour {
public Vector3 positionOne;
public Vector3 positiontwo;
public Vector3 nextposition;
public Transform plankTranform;
/*Empty object is already made on unity editor and its parent of
platform(Plank) and other
empty object "pointB". Point "B" is already mapped on editor and platform
is set to go from its original pos to point B */
public Transform positionBTransform;
public float speed;
// Use this for initialization
void Start () {
positionOne = plankTranform.localPosition;
positiontwo = positionBTransform.localPosition;
nextposition = positiontwo;
}
// Update is called once per frame
void Update () {
move();
}
private void move() {
plankTranform.localPosition = Vector3.MoveTowards(plankTranform.localPosition,nextposition,Time.deltaTime*speed);
if(Vector3.Distance(plankTranform.localPosition,nextposition)<0.1)
{ changeMovementPlank(); }
}
void changeMovementPlank() {
nextposition = nextposition != positionOne ? positionOne : positiontwo;
}
void OnCollisionEnter2D(Collision2D other)
{ if(other.gameObject.tag=="Player")
{
other.transform.SetParent(plankTranform);
}
}
void OnCollisionExit2D(Collision2D other)
{
other.transform.SetParent(null);
}
}
答案 0 :(得分:1)
SetParent(parent, true);
<强> worldPositionStays 强>
如果为true,则修改父亲相对位置,比例和旋转,使对象保持与以前相同的世界空间位置,旋转和缩放。