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 /
avatar image
1
Question by Marten · Jan 29, 2010 at 03:58 PM · rotationconfigurablejointgamecontroller

keyboard controlled configurable joint

Hi there, can any1 tell me how i setup configurable joint which i can control by W.A.S.D. keys?

i cant simply use the fpswalker for example. as the anchor is placed out its center.

TIA! :)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by duck · Jan 29, 2010 at 04:22 PM

Well, this answer would depend on what particular part of the configurable joint do you want to control? There are a lot of different settings, and you could control many of them via keyboard input.

First off, the WSAD keys (and the arrow keys) are mapped to the "Vertical" axis and "Horizontal" axis by default, so unless you've changed the input settings, you can grab these values as a range from -1 to 1 by using Input.GetAxis, like this:

Input.GetAxis("Vertical")
// and...
Input.GetAxis("Horizontal")

Then, for instance, if you wanted to control the targetRotation value of your configurable joint, you could use something like the script below in your Update() function. 'rotateSpeed' would be a float variable that determines the speed at which the target angle changes (in degrees per second), and "thisConfJoint" would be a reference to the joint being controlled. The script rotates the targetAngle of the joint around its x axis.

void Update()
{
    targetAngle += Input.GetAxis("Horizontal") * Time.deltaTime * rotateSpeed;
    Quaternion targetRotation = Quaternion.AngleAxis( targetAngle, Vector3.right );
    thisConfJoint.targetRotation = targetRotation;
}

Of course, adjusting the configurableJoint's target rotation will only have an effect if you've set up the joint's other settings correctly so that the joint automatically applies a torque force to actually reach the specified target rotation. By default, all these settings are off so it won't do anything.

To have a joint apply torque to move towards its targetAngle (in our case, just the X axis is used) you need to set up the joint properly. For this particular example, these are the settings you'd need:

  • XMotion : Locked
  • YMotion : Locked
  • ZMotion : Locked
  • Angular XMotion : Limited
  • Angular YMotion : Locked
  • Angular ZMotion : Locked
  • Rotation Drive Mode : X & YZ
  • Angular XDrive:
    • Mode : Position
    • Position Spring : 1000
    • Position Damper : 200
    • Maximum Force : 10

You will no doubt want to configure your own spring, damper and max force values to suit the mass of the objects in your scene.

I used a system very similar to the above described method to the Excavator Arm Controls in this Christmas Demo! (You can smash up ice sculptures with an excavator)

Skive Christmas Excavator Demo

(the link to play is at the bottom of the blog post)

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 Marten · Jan 29, 2010 at 06:49 PM 0
Share

Thank you!. well the use of my configjoints will be pretty much the same as in your excavator in your excavator game.. is there no way to stop the hinges from swinging around? if you rapidly rotate left/right. you can see the stick swinging out of the official joints :)

Thanks!

avatar image Jean-Fabre · Jan 05, 2012 at 04:14 PM 1
Share

Hi, I managed to achieve a excavator that doesn't swing, but it's using some extrem setup: for physics time step and such: http://www.fabrejean.net/projects/excavator/ more infos on avoiding swingings: http://answers.unity3d.com/questions/14358/non-springy-configurable-joint.html

avatar image ikelaiah · Jun 04, 2013 at 05:42 AM 0
Share

@duck If I could upvote this answer five times, I would. Thanks. You helped me to solve 2 issues. First "+=" I did not realise that I need to add the intended angle to the Quaternion. Secondly, I missed the setup on the limiting joint around axis of interest.

avatar image
0

Answer by konzon · Nov 22, 2010 at 10:57 PM

Duck,

Did you use configurable joints for the "hydraulic" components of the arms as well? If so, did you find a quick way to calculate the target angles for the piston and cylinder? I've been beating my head on this one.... Tried colliders as well. Anything you can offer in regards to the hydraulic motions would be very helpful.

I like your excavator demo - it's that time of year again!

Comment
Add comment · Show 1 · 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 konzon · Nov 23, 2010 at 10:49 PM 0
Share

Never$$anonymous$$d Duck... I figured out that by removing physics from the hydraulics I can simply use transform.LookAt to aim the hydraulic components at the appropriate target.

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

configurable joint targetrotation: How to compute it 3 Answers

Lock axis/rotation on 2d plane with capsule collider 2 Answers

Flip over an object (smooth transition) 3 Answers

How to restore a rigidbody rotation 1 Answer

Configurable joint around 2 axis 3 Answers


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