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
1
Question by TinyUtopia · May 27, 2010 at 12:06 PM · rigidbodyinputquaternionaddforce

Add rotation to rigidbody AddForce?

I am using input from the player

accel = Input.GetAxis ("Vertical") ;

to move a sphere rigidbody using

rigidbody.AddForce

I would like to use the input

turn = Input.GetAxis ("Horizontal") ;

To turn the sphere. In other words, I would like to adjust the the Quaternion of the shpere so that the forward momentum generated by rigidbody.AddForce changes direction one degree + or - as the player is pressing left, right arrows

All of my attempts result in the shpere turning, but not changing the forward momentum direction. Any ideas how to do this?

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

3 Replies

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

Answer by Tabu · Aug 08, 2010 at 01:11 PM

EDIT: Saw you wanted to use AddForce, Im not sure, but I guess this same principel should work with that also. BTW: This is done in C#

Tried to make a quick example, I think this should do the trick, Fiddle about with it, to get it to fit what your trying to do.

using UnityEngine;

using System.Collections;

public class testMovementScript : MonoBehaviour {

public Rigidbody theBody; public float moveSpeed; public float rotation; private Vector3 moveDirection;

// Use this for initialization void Start () {

}

// Update is called once per frame void Update () { transform.Rotate(Input.GetAxis("Horizontal") rotation Time.deltaTime, 0, Input.GetAxis("Horizontal") -rotation Time.deltaTime); //This is where you rotate your GameObject.

 //This is where you move the GameObject about.
 moveDirection = new Vector3(0, 0, moveSpeed * Input.GetAxis("Vertical"));
 theBody.transform.Translate(moveDirection);

}

}

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 TinyUtopia · Aug 11, 2010 at 03:51 PM 0
Share

Yes, this is exactly want I meant. I had suspected that it was by somehow using the translation conponent of the object. Very helpful!

avatar image
0

Answer by StephanK · May 27, 2010 at 02:14 PM

I'm not sure if I understood what you want to do. If you want a force that points into another direction all you have to do is rotate the force before you add it. If you want to change the direction of the momentum the sphere already has you will have to rotate the spheres rigidbody.velocity accordingly.

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

Answer by spinaljack · May 27, 2010 at 02:15 PM

You need to track the forward direction yourself as a variable and apply a constant force in that direction to maintain movement in the correct direction. Use a highish drag value to prevent the ball from picking up speed over time. When you press the left and right keys rotate the forward direction and apply a force relative to the forward direction.

Placing the sphere in a container game object will help you with keeping the correct forward direction.

It's a bit of a round about way but movement like you describe isn't very realistic.

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

1 Person is following this question.

avatar image

Related Questions

Top Down car/vehicle movement 1 Answer

How do I AddForce in the forward direction of another object? 2 Answers

GetComponent.Addforce() not working 1 Answer

How prevent addforce when clicking resume button? 1 Answer

Erratic behavior of sphere and AddForce? 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