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 Leutz · Jul 29, 2018 at 12:51 PM · rotationrigidbodymobilejoystick

Rigidbody rotation with virtual joystick, weird behaviour

This is the game i'm working on. I have a really bad time trying to figure out a problem.

With this script attached, the tank moves properly, rotates according to the joystick direction, but.. when the rank tries to climb a ramp, it appears that it goes a bit through the ramp, before climbing and acting weird.
Also, when the tank goes off a cube, it falls, but stays a bit in the air. When I release the joystick, fells faster. Lots of weird rotations also occur when simply moving.
I assume the problem is in the code that calculates the rotation, as it modifies the x and z axis. But I have no idea, after hours spending searching tutorials, how to fix this. This is my first question on a website like this. Also, sorry for my bad english.
I attached a photo of the game so that u know what I mean with those ramps. Also, the script is attached below. Thanks in advance.

alt text

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class MobileControls : MonoBehaviour {
 
     public Joystick movementJoystick;
 
     public int rotSpeed = 100;
     public float moveSpeed = 10;
     public Vector3 vec;
     public Vector3 _centerOfMasss;
     Rigidbody rb;
 
     public float joyH = 0;
     public float joyV = 0;
 
     void Start()
     {
         rb = GetComponent<Rigidbody>();
         rb.centerOfMass = _centerOfMasss;
     }
 
     private void Update()
     {
         joyH = movementJoystick.Horizontal;
         joyV = movementJoystick.Vertical;
         TryThisToRotate();
     }
     private void FixedUpdate()
     {
         Vector3 movement = new Vector3(joyH * moveSpeed * Time.deltaTime, 0, joyV * moveSpeed * Time.deltaTime);
         rb.MovePosition(transform.position + movement);
     }
 
     void TryThisToRotate()
     {
         if (joyH != 0f || joyV != 0f)
         {
             this.transform.localEulerAngles = new Vector3(this.transform.localEulerAngles.x, Mathf.Atan2(-joyH, -joyV) * Mathf.Rad2Deg, this.transform.localEulerAngles.z);
         }
     }
 }
 

screenshot-50-min.png (493.8 kB)
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 JVene · Jul 29, 2018 at 04:30 PM 0
Share

We must learn from you how the tank is configured. The description you give is recognized where any vehicle approaching an object seems to penetrate the object when the "wheels" or "tracks" haven't reached that object, like the ramp.

Without knowledge of your means of setting up the tank, all who help can only speak in generalities about that. It is a recognizable task upon which many hours have been spent learning. You can get help here, and you may find assets in the store designed to improve vehicle performance.

I've built a kind of $$anonymous$$iature monster truck (part of a robotics simulation, less of a game, more of a tool) which drives over objects and obstacles, so I recognize what you are describing. $$anonymous$$y general advice on that is if using wheel colliders as a vehicle design, they assume the track is smooth, and obstacles to climb, like a ramp, have very smooth geometric interfaces. They seem to operate like wheeled carts with very tiny wheels, where any obstacle causes major bouncing.

With all of that said, I must also advise that one either stick entirely with code manipulation of the object, or stick entirely with physics. $$anonymous$$ixing the two almost never works well - that is, direction alteration of the orientation (setting angles of the transform) while also letting physics impose gravity and handle collisions is problematic at best. Either drive by physics and steer, or drive kinetically and ignore physics.

0 Replies

· Add your reply
  • Sort: 

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

179 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 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

Single Joystick Movement 0 Answers

Make gameObject face position of Joystick [Mobile] 4 Answers

How can i rotate 3D object with joystick in all directions? 0 Answers

why is my character rotation always 180° after joystick is released. 1 Answer

Rotate a GameObject in the Vector3 direction? 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