Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 DerpMerf · Jul 24, 2015 at 08:30 PM · rigidbodymonobehaviour

Tank-Based Creation of Tank-Based Objects

I'm attempting to create a game that has tanks in it. I've created a "rough sketch" of a script that will probably be overhauled later in the development cycle. It's not working for some reason, probably because rigidbody.AddForce is the most finicky thing since we had to punch holes in paper to program computers. I'd just like to know if I'm going in the right direction or if I should overhaul it now and do something else, or what. Here's the script:

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof (Rigidbody))]
 public class TankController : MonoBehaviour {
     
     private Rigidbody rb;
     
     private Vector3 speed;
     
     void Start () {
         rb = GetComponent<Rigidbody> ();
     }
     
     void Update() {
         GetInput ();
     }
     
     void FixedUpdate() {
         MoveTank ();
     }
     
     void GetInput() {
         speed.x = Input.GetAxis ("Horizontal");
         speed.y = rb.velocity.y;
         speed.z = Input.GetAxis ("Vertical");
     }
     
     void MoveTank() {
         rb.velocity = speed;
         
         rb.AddForce(new Vector3(speed.x, 0, speed.z));
 
         Debug.Log ("Speed.x = " + speed.x + ", and Speed.z = " + speed.z);
     }
 }
 
Comment
Add comment · Show 17
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 DerpMerf · Jul 24, 2015 at 08:05 PM 0
Share

The tank simply isn't moving, which does not make sense considering I print out speed.x and speed.z and they are not 0.

avatar image Positive7 · Jul 24, 2015 at 08:50 PM 1
Share

Did you attach it to the Tank gameObject? 'Cause the script works fine here

avatar image Positive7 · Jul 25, 2015 at 08:20 AM 1
Share

Attach it to a Cube. It should move. (At least it did here without any modification of the above script)

avatar image Positive7 · Jul 25, 2015 at 01:31 PM 1
Share

As I said before the script works. So the problem is in your end. $$anonymous$$aybe your Input settings are not setup correctly. Create a new project. Add a Cube to the Scene -> Attach Script -> Disable Use Gravity in Rigidbody component(Since there is no terrain) -> Press Play. $$anonymous$$ove Cube with WASD or Arrows

avatar image Positive7 · Jul 25, 2015 at 02:35 PM 1
Share

You can't add Force or any Physics if Is $$anonymous$$inematic is checked. http://docs.unity3d.com/ScriptReference/Rigidbody-is$$anonymous$$inematic.html You can uncheck is$$anonymous$$inematic or use $$anonymous$$ovePosition ins$$anonymous$$d AddForce. http://docs.unity3d.com/ScriptReference/Rigidbody.$$anonymous$$ovePosition.html

Show more comments

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I add a rigidbody in script? 1 Answer

How to use rigidbody for characters 0 Answers

OnTriggerEnter without RigidBody 3 Answers

Rigidbody velocity has got different direction than VelocityChange force vector 1 Answer

Strange physics, rigidbody, iTween activity 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