Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Nexusty · Jun 04, 2016 at 05:05 PM · c#gameobjecttransform.positionmathfellipse

Moving a GameObject in an Ellipsoid path

I'm aware this question has been asked twice before but for some reason the code that the users provide doesn't work for me and constantly returns compiling errors.

I'm not the best at C# so I'm still learning but here is my code. using UnityEngine; using System.Collections;

 public class Elliptical : MonoBehaviour
 {
     public float x;
     public float y;
     public float a = 215f; //a is in AU, Semimajor Axis
     public float e = 0.0167f; //eccentricity of the planet
     private float b; // defined in Update(), Semiminor Axis
     private float r; // r
     private float R; // R = r'
     private float alpha; // angle theta
 
 
     // Update is called once per frame
     void Update()
     {
         var Sun = GameObject.Find("Sun");
         b = Mathf.Sqrt(Mathf.Pow(a, 2) * (1 - Mathf.Pow(e, 2))); // Finding the Semiminor Axis
         var alpha = 0f;
         var X = 0f;
         var Y = 0f;
         alpha += 10;
 
         X = x + (a * Mathf.Cos(alpha * 0.005f));
         Y = y + (b * Mathf.Sin(alpha * 0.005f));
         this.gameObject.transform.position = Sun.transform.position + Vector3(X, 0, Y);
     }
 }
 

The compiling error I get is "Expression denotes a 'type', where a 'variable', or 'value' or 'method group' was expected" .

however when I change the last line to this.gameObject.transform.position = Sun.transform.position + new Vector3(X, 0, Y);

my code compiles but doesn't do what I want. Any help would be appreciated!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Nexusty · Jun 05, 2016 at 10:34 PM

Figured it out, posting for the sake of other people. code:

 using UnityEngine;
 using System.Collections;
 
 public class what : MonoBehaviour
 {
     public float a = 215; //a is in AU, Semimajor Axis
     private float angle; // angle theta
     float speed = (2 * Mathf.PI) / 10;
     float x;
     float y;
     float e = 0.9f; // Eccentricity
 // Update is called once per frame
     void Update()
     {
         float b = Mathf.Sqrt(Mathf.Pow(a, 2) * (1 - Mathf.Pow(e, 2))); // Finding the Semiminor Axis (sqrt);
         var Planet = GameObject.Find("Planet");
         angle += speed * Time.deltaTime;
         x = Mathf.Cos(angle) * a; // a is the Radius in the x direction
         y = Mathf.Sin(angle) * b; // b is the  Radius in the y direction
         Planet.transform.position = new Vector3(x, 0, y);
 
 
     }
 }
 

Note that this script is for only ellipsoid movement and does not accurately portray the movement of planets. To do this you'll have to use Newton's law of universal gravitation equation.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Need Help (Script): UI reticle to RayCast gameObject > Transform gameObject to "hand" attached to FPS. 1 Answer

Make gun aim? 0 Answers

Scene change and creative cube game object 1 Answer

Question about Screen to World Point 0 Answers

Unity5/C# beginner here! Need some scripting help :) <3 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges