0
KSP 및 기타 우주 시뮬레이터 게임과 같은 공간에 대한 게임을 만들고있었습니다.
This is the normal orbit.
정상 궤도는 원입니다.
But this is my orbit .Unity C# 비정상적인 obit
중력을 생성하기 위해 Collider2D 및 Point effector2D를 사용해 보았지만 너무 좋지 않습니다. 나는이 문제를 해결할 수있는 방법, 나는 궤도와 같은 꽃이
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Gravity : MonoBehaviour {
public float Mass;
private List<GameObject> InRangeObjects;
// Use this for initialization
void Start() {
InRangeObjects = new List<GameObject>();
}
// Update is called once per frame
void Update() {
ApplyGravity();
}
void OnTriggerStay2D(Collider2D col)
{
List<GameObject> InRangeObjectstemp = new List<GameObject>();
InRangeObjectstemp.Add(col.gameObject);
InRangeObjects = InRangeObjectstemp;
////////////////////////////////////
}
public void ApplyGravity()
{
foreach (GameObject Ga in InRangeObjects)
{
float distance = (Ga.transform.position - transform.position).magnitude;
if (Ga.GetComponent<TotalDataStorer>().UseInGameGravity == true)
{
float GravitationalPule = (6.673e-11f * ((Mass * Ga.GetComponent<Rigidbody2D>().mass)/(distance * distance))) * Time.deltaTime;
Debug.Log(GravitationalPule);
Vector3 temp = Ga.transform.position - transform.position;
Ga.GetComponent<Rigidbody2D>().AddForce(new Vector2(temp.x, temp.y) * GravitationalPule * -1) ;
}
}
}
}
:
이 내 코드?
당신은 또한 정지 궤도에 관한 [this SE answer] (http://space.stackexchange.com/a/10867)에 관심이있을 수 있습니다. – cubrr
죄송합니다. 그 링크의 물리학을 이해할 수 없습니다. 저는 2 학년 학생 일 뿐이며, 저에게 코드 일부를 줄 수 있습니까? 도와 줘서 고마워! – Ben
(다소) 현실적인 시뮬레이션 게임을 만들고 싶다면 물리와 수학을 이해해야합니다. 그렇지 않다면 게임에 적합한 무언가를 만들어야합니다 (다른 말로 표현하면 "충분히 좋아 보인다"). – UnholySheep