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 /
This question was closed Feb 25, 2016 at 03:56 PM by Son_ofSpartacus for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Son_ofSpartacus · Feb 19, 2016 at 07:57 PM · 2dscripting beginnertop down shootercontrollers

Unity2D Top Down Tank Controller

So, I'm almost completely new to this. I'm making a top down 2d shooter with tanks. The Tanks are 2 objects (turret nested into chassis), with the chassis having rigidbody2d and a box collider. I'm having a lot of trouble figuring out how to add accurate tank controls to the chassis object. I've been looking all over, but none of the tutorials I find are really helping me. Am I doing something wrong? Will the 2 object tank just not work? Sorry if this ends up being an "oh of course, duh," question, as I said, just started unity.

I've been using C#, and haven't put any more code in because I want to get 'forwards' to work before I move on. Here's the script, though.

 using UnityEngine;
 using System.Collections;
 
 public class PlayerControls : MonoBehaviour
 {
     public float movementSpeed = 5.0f;
 
     private Rigidbody2D body2d;
 
     void Awake()
     {
         body2d = GetComponent<Rigidbody2D>();
     }
 
 
 
     // Update is called once per frame
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.W))
         {
             body2d.transform.position += transform.forward * Time.deltaTime * movementSpeed;
         }
     }
 }
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 invictus_29 · Sep 28, 2017 at 03:47 AM 0
Share

This is what I did to make it work. In your case...

 float moveBody = Input.GetAxis ("Vertical");
     
             if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.W)) {
                 body2d.transform.position += transform.right * (speed * moveBody) * Time.deltaTime;
             }



0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Projectile Instantiating at opposite position 0 Answers

Make a character face left. without flip 1 Answer

How to add limited player movement on grid? 2 Answers

How to Stop Collider from Moving? 2 Answers

Advise on scripting text adventure 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