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
0
Question by chromebandit · Jun 29, 2013 at 12:22 AM · c#javascriptconvertto

How can I change this C# code into Javascript?

I'm pretty new to Unity and I'm trying to convert the following code into Javascript (it's currently C#) so I can understand it. Can someone help me out?

using UnityEngine; using System.Collections;

public class CarControl : MonoBehaviour

{

 public GameObject RightWheel;
 public GameObject LeftWheel;

 void Start()
 {
     Vector3 center = rigidbody.centerOfMass; 
     center.y -= 1;
     rigidbody.centerOfMass = center;
 }

 void FixedUpdate ()
 {
     float h = Input.GetAxisRaw("Horizontal");

     JointMotor motor = LeftWheel.hingeJoint.motor;
     motor.force = (h!=0?1:0) * 30;
     motor.freeSpin = true;
     motor.targetVelocity = -h * 4000;

     LeftWheel.hingeJoint.useMotor = h != 0;
     LeftWheel.hingeJoint.motor = motor;

     RightWheel.hingeJoint.useMotor = h != 0;
     RightWheel.hingeJoint.motor = motor;

     rigidbody.AddRelativeTorque(0, 0, -h * 3000);


     // flip the car
     if (Input.GetButton("Fire1"))
     {
         float deltaAngle = Mathf.DeltaAngle(transform.eulerAngles.z, 0);
         if (Mathf.Abs(deltaAngle) > 10)
         {
             rigidbody.AddTorque(0, 0, deltaAngle * deltaAngle * deltaAngle, ForceMode.VelocityChange);
         }
     }
 }

}

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 robertbu · Jun 29, 2013 at 12:42 AM 1
Share

The changes needed are fairly simple...how variables are declared and how functions are declared. Learning how to do basic translation between the two languages is a good skill to have and almost a necessity when researching topics on UA. I suggest you take a stab at it yourself. If you get stuck, post your code. Here is a reference for the syntax differences:

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

avatar image Kiloblargh · Jun 29, 2013 at 03:48 AM 0
Share

Good find there, but no one asking how to convert a script from C# to JS really wants to understand it, they just want something they can copypaste into their existing copypasted script that they don't understand either.

avatar image Benproductions1 · Jun 29, 2013 at 04:11 AM 0
Share

@$$anonymous$$iloblargh That is such a wrong approach it makes me sick! Learning C# compared to javascript (or vice versa) is easy. It's just different syntax. I learned to convert from and to C# by just reading a C# script.

I'm sorry to say, but if you're not able to "understand" converting between the two languages, then you probably shouldn't be!

0 Replies

· Add your reply
  • Sort: 

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

16 People are following this question.

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

Related Questions

Help converting C# to Javascript. 1 Answer

Convert Javascript class to a string 0 Answers

Can someone convert this into javascript? :) 1 Answer

Need help converting javascript to c# script 2 Answers

C# into JavaScript 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