Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
avatar image
0
Question by ChristopherGainz · Apr 11 at 01:02 PM · movementcollisionsvehicletower defensefiring

Need help with Vehicle Movement, Collisions, Firing.

I'm pretty much new to Unity and still having trouble just doing the most basic of functions inside the programme. I need to make a Tower Defense game. I have made a tank and a building and I want the player to control the tank and fire upon enemies.
As it stands the tank stutters upon movement, the two turrets fire simultaneously instead of one or the other, the tank drives straight through the building or hits it and floats up backwards.
I have tried various edits in the inspector such as Rigidbody for both the Tank and Building, Rigidbody for one or the other, box colliders, turning on / off gravity, adjusting the mass.
There is a link with quick gameplay.
https://photos.google.com/search/_tra_/photo/AF1QipM1p3sn3_ZtsTgI1fMVYHfsYALrFya_9Lipa8ZG Here are my scripts:

public class Turret : MonoBehaviour {

 void Update()
 {

     // Rotates the turret left when the A ARROW is pressed 
     if (Input.GetKey(KeyCode.A))
     {
         transform.Rotate(0, -0.1f, 0);
     }

     // Rotates the turret right when the D ARROW is pressed 
     if (Input.GetKey(KeyCode.D))
     {
         transform.Rotate(0, 0.1f, 0);
     }
     
 }

{ public GameObject MyScript;

 // Start is called before the first frame update
 void Start()
 {

 }

 // Update is called once per frame
 void Update()
 {
     
 }

 void OnCollisionEnter(Collision other)
 {
     if (other.gameObject.tag == "building")
     {
         MyScript.GetComponent<Collisions>().enabled = true;
     }
 }

 void OnCollisionExit(Collision other)
 {
     if (other.gameObject.tag == "building")
     {
         MyScript.GetComponent<Collisions>().enabled = false;
     }
 }

}

 public GameObject projectilePrefab;  
 public Transform projectileSpawn;  
 public float projectileSpeed = 30f;    
 public float lifeTime = 3f;  
 
 
  

 void Start()
 {

 }
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.W))
     {
         FireL();
     }    
     

     if (Input.GetKeyDown(KeyCode.S))
     {
         FireR();
     }
 }

 private void FireL()
 {
     GameObject CylinderL = Instantiate(projectilePrefab);
     Physics.IgnoreCollision(CylinderL.GetComponent<Collider>(), projectileSpawn.parent.GetComponent<Collider>());
     CylinderL.transform.position = projectileSpawn.position;
     Vector3 rotation = CylinderL.transform.rotation.eulerAngles;
     CylinderL.transform.rotation = Quaternion.Euler(rotation.x, transform.eulerAngles.y, rotation.z);
     CylinderL.GetComponent<Rigidbody>().AddForce(projectileSpawn.forward * projectileSpeed, ForceMode.Impulse);
     StartCoroutine("DestroyProjectile");
 }

 private void FireR()
 {
     GameObject CylinderR = Instantiate(projectilePrefab);
     Physics.IgnoreCollision(CylinderR.GetComponent<Collider>(), projectileSpawn.parent.GetComponent<Collider>());
     CylinderR.transform.position = projectileSpawn.position;
     Vector3 rotation = CylinderR.transform.rotation.eulerAngles;
     CylinderR.transform.rotation = Quaternion.Euler(rotation.x, transform.eulerAngles.y, rotation.z);
     CylinderR.GetComponent<Rigidbody>().AddForce(projectileSpawn.forward * projectileSpeed, ForceMode.Impulse);
     StartCoroutine("DestroyProjectile");
 }
 private IEnumerator DestroyProjectile(GameObject projectile, float delay)
 {
     yield return new WaitForSeconds(delay);
     Destroy(projectile);
 }

} public class TankMovement : MonoBehaviour {

 Rigidbody m_Rigidbody;
 public float m_Speed;
 private bool isGrounded; 

 void Start()
 {
     //Fetch the Rigidbody component you attach from your GameObject
     m_Rigidbody = GetComponent<Rigidbody>();
     //Set the speed of the GameObject
     
 }
 
 void FixedUpdate()
 {

     if (Input.GetKey(KeyCode.UpArrow))
     {
         //Move the Rigidbody forwards constantly at speed you define (the blue arrow axis in Scene view)
         m_Rigidbody.velocity = transform.forward * m_Speed;         
     } 

     if (Input.GetKey(KeyCode.DownArrow))
     {
         //Move the Rigidbody backwards constantly at the speed you define (the blue arrow axis in Scene view)
         m_Rigidbody.velocity = -transform.forward * m_Speed;
     }

     if (Input.GetKey(KeyCode.RightArrow))
     {
         //Rotate the sprite about the Y axis in the positive direction
         transform.Rotate(new Vector3(0, 1, 0) * Time.deltaTime * m_Speed, Space.World);
     }

     if (Input.GetKey(KeyCode.LeftArrow))
     {
         //Rotate the sprite about the Y axis in the negative direction
         transform.Rotate(new Vector3(0, -1, 0) * Time.deltaTime * m_Speed, Space.World);

     }
 }

 
  

}

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 ChristopherGainz · Apr 11 at 01:13 PM 0
Share

These are some photo links with object properties. I realise the mass differences are all over the place and various other properties, but I have been adjusting everything over and over again.
https://photos.google.com/search/_tra_/photo/AF1QipMukrWlHY7bPLYEr9dR3hJT9I6B_YxsnL4eo_pP
https://photos.google.com/search/_tra_/photo/AF1QipM-7sQJe0vWb-D9jx0ig4Hk0Wv0smLTkJkohg_G

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

237 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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

UNET Multiplayer Vehicle Movement sync issues 0 Answers

Best possible way to implement physics on a chariot 2 Answers

Why does the FreezeRotation constraint still allow the rotation to be modified? 1 Answer

First person controls for GoogleCardboard 2 Answers

Cant Move towards Right and Jump at same time? 2 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