Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
-2
Question by UnLucky · Jul 20, 2012 at 12:43 PM ·

C# code to Java code

i have posted my code here please i deed it in java format can any one help me?

 using UnityEngine;
 using System.Collections;

 public class NetworkRigidbody : MonoBehaviour {

 public double m_InterpolationBackTime = 0.1;
 public double m_ExtrapolationLimit = 0.5;
 
 internal struct State
 {
      internal double timestamp;
      internal Vector3 pos;
      internal Vector3 velocity;
      internal Quaternion rot;
      internal Vector3 angularVelocity;
 }
 
 // We store twenty states with "playback" information
 State[] m_BufferedState = new State[20];
 // Keep track of what slots are used
 int m_TimestampCount;
 void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) {
  // Send data to server
  if (stream.isWriting)
  {
      Vector3 pos = rigidbody.position;
      Quaternion rot = rigidbody.rotation;
      Vector3 velocity = rigidbody.velocity;
      Vector3 angularVelocity = rigidbody.angularVelocity;
      stream.Serialize(ref pos);
      stream.Serialize(ref velocity);
      stream.Serialize(ref rot);
      stream.Serialize(ref angularVelocity);
  }
 
  // Read data from remote client
  else
  {
      Vector3 pos = Vector3.zero;
      Vector3 velocity = Vector3.zero;
      Quaternion rot = Quaternion.identity;
      Vector3 angularVelocity = Vector3.zero;
      stream.Serialize(ref pos);
      stream.Serialize(ref velocity);
      stream.Serialize(ref rot);
      stream.Serialize(ref angularVelocity);
 
      // Shift the buffer sideways, deleting state 20
      for (int i=m_BufferedState.Length-1;i>=1;i--)
      {
          m_BufferedState[i] = m_BufferedState[i-1];
      }
 
      // Record current state in slot 0
      State state;
      state.timestamp = info.timestamp;
      state.pos = pos;
      state.velocity = velocity;
      state.rot = rot;
      state.angularVelocity = angularVelocity;
      m_BufferedState[0] = state;
 
      // Update used slot count, however never exceed the buffer size
      // Slots aren't actually freed so this just makes sure the buffer is
      // filled up and that uninitalized slots aren't used.
      m_TimestampCount = Mathf.Min(m_TimestampCount + 1,
      m_BufferedState.Length);
 
      // Check if states are in order, if it is inconsistent you could reshuffel or
      // drop the out-of-order state. Nothing is done here
      for (int i=0;i interpolationTime)
      {
          // Go through buffer and find correct state to play back
          for (int i=0;i 0.0001)
              t = (float)((interpolationTime - lhs.timestamp) / length);
          // if t=0 => lhs is used directly
          transform.localPosition = Vector3.Lerp(lhs.pos, rhs.pos, t);
          transform.localRotation = Quaternion.Slerp(lhs.rot, rhs.rot, t);
          return;
      }
  }
 }
  // Use extrapolation
  else
  {
  State latest = m_BufferedState[0];
  float extrapolationLength = (float)(interpolationTime - latest.timestamp);
  // Don't extrapolation for more than 500 ms, you would need to do thatcarefully
  if (extrapolationLength < m_ExtrapolationLimit)
  {
      float axisLength = extrapolationLength * latest.angularVelocity.magnitude
      * Mathf.Rad2Deg;
      Quaternion angularRotation = Quaternion.AngleAxis(axisLength,latest.angularVelocity);
      rigidbody.position = latest.pos + latest.velocity * extrapolationLength;
      rigidbody.rotation = angularRotation * latest.rot;
      rigidbody.velocity = latest.velocity;
      rigidbody.angularVelocity = latest.angularVelocity;
  }
  }
  }

}

Comment
Add comment · Show 3
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
avatar image Bunny83 · Jul 20, 2012 at 12:48 PM 5
Share

This is not a free online code converting service. Also you didn't format your code...

-1

Btw. The language is called UnityScript or Javascript. Java is something completely different.

avatar image tw1st3d · Jul 21, 2012 at 03:12 PM 0
Share

Please put this into a Code Block so we can read it properly.

avatar image AlucardJay · Jul 21, 2012 at 04:47 PM 0
Share

roughly formatted now. @UnLucky please format your own code in future using the 10101 button, or adding 4 spaces before every line as I just have. This is alot of code, you won't find someone to convert it for you unless they knew what you want, and have done the same themselves, and decide to give away all their hard work. There's no description even on whet the script does, what you want it to do, and if you have tried and are stuck.

Here's some links I found useful in converting between C# and JS :

http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html

http://www.unifycommunity.com/wiki/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use?

if you need this script , you may be able to use it as C# : it is possible to use both languages, but the way they compile means that they only work one way i.e. C# gets compiled before JS, JS can see C# but C# cannot see JS :

http://docs.unity3d.com/Documentation/ScriptReference/index.Script_compilation_28Advanced29.html => point 3

http://answers.unity3d.com/questions/208383/referencing-a-c-component-script-from-js-script.html

http://answers.unity3d.com/questions/243112/calling-c-classes-from-js.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by everett24 · Jul 21, 2012 at 04:23 PM

Um my answers not going to be very exciting, you can go google "c# to javascript converter" things actually come up for that, I used it myself when taking my Javascript to c#

Hope this helped a little

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Why does this script make my camera upside down? 0 Answers

How to toggle a key for a car to go forward or backward? 1 Answer

Error whit c# code 'UnityEngine.Transform.position' because it is not a variable. 1 Answer

Collider doesn't transfer to function 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