I also made each planet rotate around the sun at a specific speed by dividing their actual orbital velocities with that of the Earth to obtain a non-dimensional rate. Here is a snippet of code for one of those planets' rotation:
The rest were almost the same except for the class name and the third transform value, which would be different for every planet in accordance to their velocity. In addition to this, I added a first-person camera that can move along the x and y axes with the WASD keys, and rotate in 3 degrees of freedom using the mouse:
That's it for today, nothing too involving. Tomorrow I will show my third C# program-a differential equation solver that makes use of Euler's method to complete its calculations.
using System.Collections; using System.Collections.Generic; using UnityEngine; public class rotate_earth : MonoBehaviour { void Start () { } void Update () { transform.RotateAround(transform.position, new Vector3(0, 1, 0), 1.0f); } }
using System.Collections; using System.Collections.Generic; using UnityEngine; public class first_person_cam : MonoBehaviour { public float speedH = 1.0f; public float speedV = 1.0f; private float yaw = 0.0f; private float pitch = 0.0f; float x = 1.0f; float y = 1.0f; float z = 1.0f; void Start () { } void Update () { yaw += speedH * Input.GetAxis("Mouse X"); pitch -= speedV * Input.GetAxis("Mouse Y"); transform.eulerAngles = new Vector3(pitch, yaw, 0.0f); x = Input.GetAxis("Horizontal"); y = Input.GetAxis("Vertical"); z = Input.GetAxis("ZMove"); transform.Translate(x, y, z); } }
No comments:
Post a Comment