I have a tank in unity and this code. I am trying to just set it up so that the tank will move. I am brand new to this and can’t figure out how to use the Character Controller in conjunction with GameO
I am really just trying to set up everything in the start and beginning right now.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TankMotion : MonoBehaviour
{
public GameObject tankBody;
public GameObject turret;
public GameObject chassis;
// Vector3 player;
public CharacterController control;
public float speed = 6.0f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
private Vector3 moveDirection = Vector3.zero;
// Use this for initialization
void Start()
{
control = turret.GetComponent<CharacterController>();
//player = tankBody.transform.position;
}
// Update is called once per frame
void Update()
{
/*Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
_controller.Move(move * Time.deltaTime * Speed);*/
if (control.isGrounded)
{
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
moveDirection *= speed;
if (Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
}
// Move the controller
control.Move(moveDirection * Time.deltaTime);
}
}
bject