简体   繁体   English

我正在尝试在 Unity 中执行传送脚本 3d 我不是专家

[英]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.

相关问题 我正在使用 unity 3D 2018 并且下面的代码出现此错误如何更改 MinAttribute 以与我正在运行的统一版本兼容? - I'm using unity 3D 2018 and I have this error with the code below how do I change MinAttribute to be commpable with the version of unity i'm running? 我目前正在做一个统一的 3d 战斗课程,我坚持这个 - I'm currently doing a unity 3d combat course and i'm stuck on this 我正在努力使玩游戏的人可以在触发器中按他们想要的次数按“E” | Unity 3d + 动画师 - I'm trying to make it so the person playing the game can press "E" as much as they want in the trigger | Unity 3d + animator 我正在尝试让我的 2D 统一角色跳跃 - I'm trying to make my 2D unity character jump 如何为 Unity 3D 修复此脚本 - How do I fix this script for Unity 3D 我正在尝试使用以前的运动脚本来实现统一,但出现了同样的错误? (对于统一 2d) - I'm trying to use previous movement scripts for unity but get the same error? (For unity 2d) 我正在尝试将Java脚本统一转换为csharp脚本,但出现一些错误? - I'm trying to convert java script in unity to csharp script but getting some errors? 在Block Breaker游戏中(Unity3D)我试图在所有积木都毁掉时加载关卡 - (Unity3D) in Block Breaker game I'm trying to load levels when all bricks destroyed 我的统一 2d 运动脚本中有很多错误 - I'm getting so many errors in my unity 2d movement script 我正在尝试将一个脚本中的 var 值从 c# 中的另一个统一更改 - I'm trying to change var value in one script from another in c# in unity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM