The question is answered, right answer was accepted
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;
}
}
}
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;
}
Follow this Question
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