• 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 Narv · Aug 24, 2013 at 06:03 PM · movementrigidbodylerpjoystickforce

Gameobject is climbing out objects with rigidbody

So I have a player, that is a tank. I have a bounding box on the tank and a rigidbody attached to it for collisions. I am using a joystick from the package EasyTouch 3 to use move the tank around. However, I am having difficulty with the movement of the tank and its interactions with the world. I understand WHY im having some of the issues I am having, just not sure on how to fix them, or the best approach.

So here is my setup: The movement joystick right now is simply sending its X and Y (from -1 to 1) to the camera script which is also moving the tank (and the camera is following the tank). The camera is looking down at the tank at about a 45 degree angle. When it receives the "on_joystickmove" event from the easytouch asset, it then moves the tank accordingly.

The asset does have a way of moving object on its own, however it's setup to have the joystick pointing up be forward, regardless of how the tank is facing. The mechanic I am going for is the tank goes in the direction the joystick is facing.. Point it left, it goes to the left, etc. So I am using the events that fire off to move my guy.

I had difficulty moving the tank with velocity, addforce, etc. So I used this:

             Vector3 point = new Vector3(follow.transform.position.x + (move.joystickAxis.y * -2), follow.transform.position.y , follow.transform.position.z + (move.joystickAxis.x * 2));
             follow.transform.position = Vector3.Lerp(follow.transform.position, point, Time.deltaTime * 8 * currentSpeed);
         
             Vector3 turn = new Vector3(follow.transform.position.x + (move.joystickAxis.y * -2), follow.transform.position.y , follow.transform.position.z + (move.joystickAxis.x * 2));
             follow.transform.rotation = Quaternion.Lerp(follow.transform.rotation, Quaternion.LookRotation(turn - follow.transform.position), Time.deltaTime * 5);

This is a basic lerp for movement. Basically I was projecting the x and y axis down to the x and z axis and picking a point right in front of the tank (or to the sides) and moving it to that position over time. I messed with the numbers and such to get it to a point where I like it. However this causes issues with collision because it will try and lerp it through a bounding box and cause the tank to climb any building, or have the rigidbody on it react to the phyics of hitting a box and overlapping it and cause the tank to fly in the air. Otherwise, the tank moves PERFECTLY in how I want it to move and interact with the joysticks.

So I know with the rigidbody I could add a force and it would stop on collision and not move, but I cannot seem to get this to work right. I have found a bunch of examples, and the car tutorial but none of these translate well into using a joystick (as they all use keys, or the input axis)

I have tired: follow.rigidbody.velocity = follow.transform.forward 15 currentSpeed;

Which moves it forward just fine, though im not getting the ease in and out effect of using the joystick not 1 values, so by multiplying those values in (as ABS) it kind of jumps around.

I also tried from the wiki: float x = move.joystickAxis.x 8; float y = move.joystickAxis.y 8;

 if(follow.rigidbody.velocity.magnitude < 15)
 {
     follow.rigidbody.AddForce(follow.transform.rotation * Vector3.forward * y);
     follow.rigidbody.AddForce(follow.transform.rotation * Vector3.right * x);
 }

But it doesn't move at all. Any ideas would be greatly appreciated.

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 Narv · Aug 25, 2013 at 06:45 PM 0
Share

Anyone have any input?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

How to fix/clamp rigidbody dir vector, despite Force dir 1 Answer

Movement Physics: Max Speed and Momentun 0 Answers

Jumping increases movement speed 1 Answer

Erratics movements from my rigidbody : why does it behave like that? 0 Answers

Bug, while checking if rigidbody is moving 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