[英]I'm trying to do a teleport script in Unity 3d I'm not an expert
Here is the script but when I load it shakes the ground and then slowly vibrates behind the character the teleport itself kinda works这是脚本但是当我加载它时它会震动地面然后在角色后面慢慢振动传送本身有点工作
public float range = 1000f;
public float tprange = 100f;
private Transform Destination;
public int mana = 100;
public int currentmana;
public Camera Camera;
public GameObject Player;
public ManaBar ManaBar;
bool isteleporting;
void Start()
{
currentmana = mana;
ManaBar.SetMaxMana(mana);
isteleporting = false;
}
void Update()
{
if (Input.GetKey(KeyCode.E))
{
teleport(20);
}
}
void teleport(int consume)
{
currentmana -= consume;
ManaBar.SetMana(currentmana);
isteleporting = true;
RaycastHit hit;
if (Physics.Raycast(Camera.transform.position, Camera.transform.forward, out hit))
{
if (hit.rigidbody )
{
GameObject impactGO;
Player.transform.position = hit.point;
}
}
}
Çağatay IŞIK is right. Çağatay IŞIK 是对的。 The code works but it sends you right in to the place your raycast hit.
该代码有效,但它会将您直接发送到光线投射命中的位置。 Which means half of you is inside that hitbox.
这意味着你们有一半人在那个碰撞箱里。 Than Unity collision physics slowly move your player out of the wall.
比 Unity 碰撞物理缓慢地将你的玩家移出墙。 You need to do something like this:
你需要做这样的事情:
float playerSize = 10;
Player.transform.position = hit.point - ((hit.point - Player.transform.position).normalized * playerSize);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.