gpt4 book ai didi

c# - 如何在知道方向、角度和距离的情况下找到位置?

转载 作者:太空宇宙 更新时间:2023-11-03 14:40:19 25 4
gpt4 key购买 nike

enter image description here

使用提供的图表,我知道:

  • 角色在位置 A,面向 B (posA)
  • 物体位于位置 B (posB),面向随机方向。
  • C (desiredAngle) 的所需角度 (20),基于 A 到 B 的方向。
  • B到C的距离

我将如何找到 C 的位置?

在下面的代码中,我设法获得了向量 BC,现在如何使用从 A 到 B 的距离定义该向量上的一个点?

//The angle of the hand in relation to the object
public float angleFromPlayer = -60f;

//Get the direction vector from the selectedObject to the actor
Vector3 objectDirectionToActor = actorParent.position - selectedObjectCenter;

//Make it horizontal (Flatten the y)
objectDirectionToActor.y = 0;

//Get the rotated vector using the desiredAngle
Vector3 rotatedVector = Quaternion.Euler(0, angleFromPlayer, 0) * objectDirectionToActor;

最佳答案

弄清楚了,这是后代的解决方案:

//How high the hand will be from the dropSurface/selectedObjectPivot
public float handOffsetFromDropSurface = 0.15f;

//The angle of the hand in relation to the object
public float targetAngleFromPlayer = -80f;

//Extra distance between selectedObjectCenter and wristBone (since the handDistance is a bit too short)
public float extraHandDistance = 0f;

Vector3 GetHandBonePositionForDropSurface(Vector3 selectedObjectCenter) {
//Get the direction vector from the selectedObject to the actor
Vector3 objectDirectionToActor = actorParent.position - selectedObjectCenter;

//Make it horizontal (Flatten the y)
objectDirectionToActor.y = 0;

//Change vector size to 1 for multiplication
objectDirectionToActor.Normalize();

//Get the rotated vector using the desiredAngle
Vector3 rotatedVector = Quaternion.Euler(0, targetAngleFromPlayer, 0) * objectDirectionToActor;

//Get the distance we want the point to be from the center of the selectedObject
float handDistance =
Vector3.Distance(playerProperties.boneRightIndexProximal.position,
playerProperties.boneRightHand.position) + extraHandDistance;

//Resize vector to match the hand distance
rotatedVector *= handDistance;

//Get finalPosition, adding the handOffsetFromDropSurface
Vector3 wristTargetPosition = selectedObjectCenter + rotatedVector + (Vector3.up * handOffsetFromDropSurface);

return wristTargetPosition;
}

关于c# - 如何在知道方向、角度和距离的情况下找到位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57211929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com