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
0
Question by Dzentsetsu · Dec 16, 2017 at 02:40 PM · controllersphere

Sphere control

What can I use to move a simple sphere despite of AddForce and simple transform.Translate throw Axis input?

I ask this question because both approaches have there own limitations. For example AddForce seems not very sensitive to Input. Translate vice versa very sensitive but if your sphere flips over axis changes and ypu start moving in the wrong directions.

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 Tom507 · Dec 16, 2017 at 04:38 PM 0
Share

if you want to keep moving in the same direcition with translate, calculate the vectors in a parent object and then convert them to local space of the object you want to move

1 Reply

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

Answer by Tom507 · Dec 16, 2017 at 04:14 PM

You can use the addforce = the Rigidboddy in ways that are verry controllable, by limiting the max velocity and increasing the drag and force that is applyed, there are other ways of making it move but i believe the simplest is this. here is a simple fps controller example :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class FPS_Controller    : MonoBehaviour {
 
     public float Accellaration = 100;
     public float maxSpeed = 2;
     public float JumpHeight = 3;
 
     public float MouseSpeed = 3;
     public GameObject Camera; // you need to set this to the camera you want to use
     public float Zoffset= 90;
 
     private float LookAngleX = 0;
     private float LookAngleY = 0;
 
     private Rigidbody rb;
     private Vector3 movement;
     private Vector2 XYmovement;
     private  float Jump;
 
     void Start () {
         rb = gameObject.GetComponent<Rigidbody>();
     }
 
     void FixedUpdate (){
 
         //###################### Movement ###############################
         float moveVert = Input.GetAxis ("Vertical");
         float moveHor = Input.GetAxis ("Horizontal");
 
         XYmovement = new Vector2 (rb.velocity.x, rb.velocity.z);
 
         if( XYmovement.magnitude > maxSpeed)// clamping speed to max speed
         {
             XYmovement = XYmovement.normalized * maxSpeed;
             rb.velocity = new Vector3 (XYmovement.x, rb.velocity.y, XYmovement.y);
         }
 
         if (Input.GetButtonDown ("Jump")) {
             Jump = JumpHeight;
         }
 
         movement = new Vector3 (moveVert, Jump, -moveHor);
         movement = transform.TransformDirection (movement);
 
         rb.AddForce (movement*Accellaration);
 
 
         //##################### Mouse Controll ##########################
         // Taking controller mouse input
         var Xin = Input.GetAxis ("Mouse X");
         var Yin = Input.GetAxis ("Mouse Y");
 
         LookAngleX += Xin * MouseSpeed;
         LookAngleY += Yin * MouseSpeed;
 
         LookAngleY = Mathf.Clamp (LookAngleY, -70f, 89f);
 
         Camera.transform.localEulerAngles = new Vector3(-LookAngleY, Zoffset, 0f);
         transform.eulerAngles = new Vector3(0f, LookAngleX, 0f);
 
         Jump = 0f;
 
     }
 }

you can just slap this on a ball with a rigidbody component place a camera over it and constrain the rigidbody rotation (all axis) in the drop down in editor, drag and drop the camera object on your ball in your hirarchy (make it a child of the ball) and in the slot in the script that is meant for it and you are done.

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

75 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Guiding a sphere 2 Answers

Move 3D rigidbody sphere in the direction of it's rotation, controlled by the mouse. 0 Answers

Making a torque-based sphere controller by simple mouse inputs 2 Answers

Ways to make a ball delivery system, based on a back/down swing. 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