我是新来的,我是一个团结的初学者。对于我的游戏,我导入了一个戒指,我创建了一个3建模软件。现在我想找出那个戒指的中心。此外,我想跟踪这个环的中心位置,并把它放在一个向量中。请帮帮忙。我该怎么做?
谢谢!
编辑:
谢谢你的回答,很抱歉我说得不够具体。为了更清楚地知道我想尝试什么,我给你一些我想做的事情的信息。我会创造一个“热电线游戏”与正弦波移动电线,必须跟着一个戒指。这个游戏的目的是,环的中心必须在电线上。因此,如果玩家不够精确,就会有一个错误(期望的位置是移动的电线-实际位置,它将是圆环的中心)。
下面是我最后想要的内容的链接:
https://itunes.apple.com/de/app/hot-wire-heisser-draht/id941657787?mt=8
https://processing.org/examples/sinewave.html
到目前为止,我已经得到了由多个球构成的运动正弦波的编码。在这里,代码:
using UnityEngine;
using System.Collections;
public class SineWaveSpheres : MonoBehaviour {
public GameObject plotPointObject; public int numberOfPoints= 100;
private float animSpeed =1.0f; public float scaleInputRange = 8*Mathf.PI; // scale number from [0 to 99] to [0 to 2Pi] //Zahl vor Mathf, Anzahl Bön
public float scaleResult = 2.5f; // Y Achse Range
public bool animate = true;
public Vector3 posSphere;
GameObject[] plotPoints;
// Use this for initialization
void Start () {
if (plotPointObject == null) //if user did not fill in a game object to use for the plot points
plotPointObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); //create a sphere
//add Material to the spheres , load material in the folder Resources/Materials
Material myMaterial = Resources.Load("Materials/green", typeof(Material)) as Material;
plotPointObject.GetComponent<MeshRenderer> ().material = myMaterial;
//change the scale of the spheres
plotPointObject.transform.localScale = Vector3.one * 0.5f ;
plotPoints = new GameObject[numberOfPoints]; //creat an array of 100 points.
//plotPointObject.GetComponent<MeshRenderer>().material =Material.Load("blue") as Material
//plotPointObject.transform.localScale -= new Vector3 (0.5F, 0.5F, 0.5F); //neu: change the scale of the spheres
for (int i = 0; i < numberOfPoints; i++)
{
plotPoints[i] = (GameObject)GameObject.Instantiate(plotPointObject, new Vector3(i - (numberOfPoints/2), 0, 0), Quaternion.identity); //this specifies what object to create, where to place it and how to orient it
} //we now have an array of 100 points- your should see them in the hierarchy when you hit play
plotPointObject.SetActive(false); //hide the original
}
// Update is called once per frame
void Update() {
for (int i = 0; i < numberOfPoints; i++)
{
float functionXvalue = i * scaleInputRange / numberOfPoints; // scale number from [0 to 99] to [0 to 2Pi]
if (animate) {
functionXvalue += Time.time * animSpeed;
}
plotPoints[i].transform.position = new Vector3(i - (numberOfPoints/2), ComputeFunction(functionXvalue) * scaleResult, 0);
// put the position information of sphere clone 50 in a vector3 named posSphere posSphere = plotPoints [50].transform.position;
}
//print position of sphere 50 in console //print (posSphere);
}
float ComputeFunction(float x)
{
return Mathf.Sin(x);
}
}就像我说的,我有一个3D建模软件的戒指。环的中心似乎是原点(0,0,0)。因此,我的想法是,我可以执行以下操作来计算错误:
error=posSphere-posRing 在posSphere中,我会从上面的SineWave脚本中获取,而posRing则会从环形脚本中获取
posRing=transform.position;我错了吗?
我的问题:
发布于 2016-03-09 22:28:54
好吧,这有很多要解释的。首先,您有一个很好的代码,但它与您的问题无关,对吗?但无论如何,这是IMHO的答案
问题是,我不建议你这样检查玩家是否失败,我的意思是,你可以做一次碰撞检查:
void OnCollisionEnter (Collision col)
{
if (col.gameObject.name == "the name of the sine wave spehere gameobject")
{
//game over, do stuff
}
}必须将此代码添加到附加到环GameObject的脚本中。
这样你就不用担心环的中心和矢量的数学问题了。唯一要记住的是,你必须在圆环和球体预置中加入一个对撞机才能被实例化。
我就是这么想的,希望能帮上忙!^^
https://stackoverflow.com/questions/35892478
复制相似问题