Joystick Pack这种重力带惯性不利于正常开发。决定进行优化。有一种万事俱备只欠东风的感觉。
源代码如下:
1.在脚本中找到轮盘所输出的方向值
2.把方向的改变值加到鸣人模型身上。
2.1控制器脚本中添加model变量
2.2在unity中赋值
2.3代码中修改位置
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JoystickPlayerExample : MonoBehaviour
{
public float speed;//这个可以在unity中赋值的
public VariableJoystick variableJoystick;
public Rigidbody rb;
public GameObject model;
public void FixedUpdate()
{
Debug.Log(variableJoystick.Vertical);
Debug.Log(variableJoystick.Horizontal);
//计算方向差
Vector3 direction = Vector3.forward * variableJoystick.Vertical + Vector3.right * variableJoystick.Horizontal;
//rb.AddForce(direction * speed * Time.fixedDeltaTime, ForceMode.VelocityChange);//重力体不满足条件
model.transform.position = model.transform.position + direction;
}
}
3.成功移动
3.1初始位置
3.2移动后的位置
<iframe allowfullscreen="true" data-mediaembed="csdn" frameborder="0" id="c9AwqEAP-1710993532398" src="https://live.csdn.net/v/embed/372596"></iframe>摇杆移动
标签:direction,Vector3,unity,public,variableJoystick,66,model,Joystick From: https://blog.csdn.net/qq_27863281/article/details/136895345