ui 추가
This commit is contained in:
67
Assets/Scripts/MoveRobotArm.cs
Normal file
67
Assets/Scripts/MoveRobotArm.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
public class MoveRobotArm : MonoBehaviour
|
||||
{
|
||||
public Transform target;
|
||||
public Transform endPoint;
|
||||
public enum eRobotArmRotateAxis
|
||||
{
|
||||
x, y, z
|
||||
}
|
||||
[Serializable]
|
||||
public struct stRobotArmJoint
|
||||
{
|
||||
public Transform jointTransform;
|
||||
public eRobotArmRotateAxis axisType;
|
||||
public float angle;
|
||||
public float maxAngle;
|
||||
public float minAngle;
|
||||
public float baseAngle;
|
||||
public float gradient;
|
||||
public float delta;
|
||||
public void Rotate(float angle)
|
||||
{
|
||||
switch (axisType)
|
||||
{
|
||||
case eRobotArmRotateAxis.x:
|
||||
jointTransform.eulerAngles = new Vector3(angle, jointTransform.eulerAngles.y, jointTransform.eulerAngles.z);
|
||||
break;
|
||||
case eRobotArmRotateAxis.y:
|
||||
jointTransform.eulerAngles = new Vector3(jointTransform.eulerAngles.x, angle, jointTransform.eulerAngles.z);
|
||||
break;
|
||||
case eRobotArmRotateAxis.z:
|
||||
jointTransform.eulerAngles = new Vector3(jointTransform.eulerAngles.x, jointTransform.eulerAngles.y, angle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public List<stRobotArmJoint> joints = new List<stRobotArmJoint>();
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
for (int i = 0; i < joints.Count; i++)
|
||||
{
|
||||
stRobotArmJoint joint = joints[i];
|
||||
joint.gradient = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (target == null)
|
||||
return;
|
||||
for (int i = 0; i < joints.Count; i++)
|
||||
{
|
||||
stRobotArmJoint joint = joints[i];
|
||||
float distance = Vector3.Distance(target.position, endPoint.position);
|
||||
float angle = joint.angle;
|
||||
joint.Rotate(angle + joint.gradient);
|
||||
float checkDistanceP = Vector3.Distance(target.position, endPoint.position);
|
||||
joint.Rotate(angle - joint.gradient);
|
||||
float checkDistanceN = Vector3.Distance(target.position, endPoint.position);
|
||||
//if (checkDistanceP > )
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/MoveRobotArm.cs.meta
Normal file
2
Assets/Scripts/MoveRobotArm.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 939a8d4e03d60b64cbed597bedfe7923
|
||||
Reference in New Issue
Block a user