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 haim96 · Jul 26, 2014 at 07:19 PM · 2d physicsmotor

how to setup wheeljoint2D motor by code?

Hello all!

i'm trying to setup simple 2d car physics. i have a car with two WheelJoint2D component. each one of them hold one wheel. every thing is working fine beside the fact that i can't setup the motor by code (C#) here my simple script that should set the motor to -1000 and make the car jump with space key. (ignore that fact that it will jump once)

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
 
     private bool isGrounded= true;
 
     public float Power;
     public float speed;
     public WheelJoint2D wheelj1; // draged to this one the front wheel WheelJoint2D
     public WheelJoint2D wheelj2; // draged to this one the back wheel WheelJoint2D
 
     public JointMotor2D wheelj1jm;
     public JointMotor2D wheelj2jm;
 
 
     // Use this for initialization
     void Start () {
         speed = -1000f;
         wheelj1jm = wheelj1.motor;
         wheelj2jm = wheelj2.motor;
 
         wheelj1.useMotor=true;
         wheelj1jm.motorSpeed = speed; // try to setup the motor speed - nothing happen!
     
     }
     
     // Update is called once per frame
     void FixedUpdate () {
 
 
         if(Input.GetKey(KeyCode.Space) && isGrounded ){
             this.rigidbody2D.AddForce(transform.up * Power);
             isGrounded=false;
         }
     
     }
 }
 

i tried to find some sample code for this but couldn't find any. i don't get any error but the motor don't get i value -1000. what am i doing wrong? thanks!

Comment
Add comment · Show 1
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 haim96 · Jul 27, 2014 at 06:04 AM 0
Share

any one? should be easy task for you guys...

1 Reply

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

Answer by Hazlo · Jul 27, 2014 at 10:13 AM

Have you tried adding "wheelj1.motor = wheelj1jm;" after setting "wheelj1jm.motorSpeed = speed;" ?

Comment
Add comment · Show 3 · 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
avatar image haim96 · Jul 27, 2014 at 10:48 AM 0
Share

not yet, but i will later today. it might work... thanks so far.

avatar image haim96 · Jul 27, 2014 at 03:14 PM 0
Share

yap! this did the trick! thanks a lot!

avatar image Hazlo · Jul 27, 2014 at 09:52 PM 0
Share

You're welcome! :)

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

24 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I change 2d motor speed from a script? 1 Answer

2D Car problem with motor 0 Answers

Character In Need Of Exorcism 1 Answer

Can you explain me please in more details what is motorTorque? 1 Answer

2D Physics, cannot pass -10 (y-axis) 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