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 /
  • Help Room /
avatar image
0
Question by seandolan · Feb 21, 2018 at 11:13 PM · rigidbodyforcethrust

Apply force to character based on thrusters attached to a hand like objects (multiple sources)

I have a rigidbody character with 2 capsule objects to represent it's hands. These hands are going to have thrusters attached to them to propel the character based on the direction and a float value of how much force is to be applied. The hands can rotate in all directions. I have attached a Debug.DrawRay in the picture that is longer depending on how much force to apply.

If both hands are pointing directly up, the character should be moved upward.

I know that I will probably need to provide more information to clarify the desired outcome, I am just not sure what information that will be at this stage. Below I have included my current code and an image of what I am trying to work with.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerController : MonoBehaviour {
 
     Rigidbody rb;
 
     public GameObject leftHand;
     public GameObject rightHand;
     public GameObject feet;
     public GameObject thrustTarget;
 
     public float playerHeight = 1.6f;
 
     public float leftThrust = 0.0f;
     public float rightThrust = 0.0f;
 
     public float leftThrustMax = 100.0f;
     public float rightThrustMax = 100.0f;
 
     public float leftFuel = 100.0f;
     public float rightFuel = 100.0f;
 
     public float leftAcc = 10.0f;
     public float rightAcc = 10.0f;
 
     public float leftDec = 10.0f;
     public float rightDec = 10.0f;
 
     void Start () {
         rb = GetComponent<Rigidbody>();
         feet.transform.position = new Vector3(0,-playerHeight,0);
     }
 
     void Update () {
 
         if(Input.GetKey("a")) {
             leftThrust += leftAcc * Time.deltaTime;
         } else {
             leftThrust -= leftDec * Time.deltaTime;
         }
 
         if(Input.GetKey("d")) {
             rightThrust += rightAcc * Time.deltaTime;
         } else {
             rightThrust -= rightDec * Time.deltaTime;
         }
 
         if(leftThrust > leftThrustMax) { leftThrust = leftThrustMax; }
         if(rightThrust > rightThrustMax) { rightThrust = rightThrustMax; }
 
         if(leftThrust < 0) { leftThrust = 0; }
         if(rightThrust < 0) { rightThrust = 0; }
     }
 
     void FixedUpdate () {
         Debug.DrawRay(leftHand.transform.position,-leftHand.transform.up * (leftThrust / 100),Color.red);
         Debug.DrawRay(rightHand.transform.position,-rightHand.transform.up * (rightThrust / 100),Color.red);
 
         
     }
     
 }
thrust.png (159.1 kB)
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

1 Reply

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

Answer by seandolan · Feb 21, 2018 at 11:54 PM

I added the following and it seemed to work. Will leave this here for others in case it helps:

 rb.AddForceAtPosition(leftHand.transform.up * leftThrust/10),transform.position,ForceMode.Acceleration);
 rb.AddForceAtPosition(rightHand.transform.up * (rightThrust/10),transform.position,ForceMode.Acceleration);

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

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

Related Questions

rigidbody.AddForce doesn´t work in c# 1 Answer

Unity Rigidbody2D AddForce to move until certain position reached 0 Answers

Getting the net-force vector on a rigidbody 0 Answers

Player knockback in networking (Rigidbody) 0 Answers

How to apply a force at certain point of an object? 0 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