Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Sipi2000 · Aug 06, 2014 at 06:37 PM · c#2dtopdowntanktop down

Difficulty with my tank game

I have a game (top down 2d) and i have several problems The whole project can be downloaded here https://www.mediafire.com/?f0n0grifi7m5ccg I have 5 scripts and the problems are the following: Script #1 Move Problem:The tank never rotates to the right when i press "D"

 using UnityEngine;
 using System.Collections;
 
 public class Move : MonoBehaviour {
     public float speed;
     public float rotspeed;
     void Update () {
     if (Input.GetKey (KeyCode.W))
                         transform.Translate (new Vector2 (0, speed * Time.deltaTime));
     if (Input.GetKey (KeyCode.S))
             transform.Translate (new Vector2 (0, -speed * Time.deltaTime));
     if (Input.GetKey (KeyCode.A))
             transform.Rotate (new Vector3 (0,0, rotspeed * Time.deltaTime));
     if (Input.GetKey (KeyCode.D))
             transform.Translate (new Vector3 (0,0, -rotspeed * Time.deltaTime));
 
     }
 }
 

Script #2 Shell Problem:The tanks bullets clone Shell(clone) should ignore collision with the tank(because the bullet has the script and it gets cloned)

 using UnityEngine;
 using System.Collections;
 
 public class Shell : MonoBehaviour {
     public Transform Hull;
     void Start() {
         Physics.IgnoreCollision(Hull.collider, collider);
     }
 }

Script #3 Health Problem:**The tank has a HP system(very basic),the tank should take damage from the Shell2(Clone)<- The enemys bullets clone(Not tested yet-no enemy yet-)but
the tank disappears after entering playmode after 2-3seconds or not and it gets a -12 z transform(A 2D GAME) here is the script

 using UnityEngine;
 using System.Collections;
 
 public class Health : MonoBehaviour {
     public float health;
     public float dam;
     void OnCollisionEnter2D (Collision2D col) 
     {
     if (col.gameObject.name == "Shell2(Clone)") 
         {
             health = health-dam;
         }
     if (health <= 0)
                         Destroy (this.gameObject);
     }
 }

 The other scripts and the whole project can be downloaded here https://www.mediafire.com/?f0n0grifi7m5ccg

Thanks if you can help me Oh and what do you think of the game thats my first one? The other scripts and the whole project can be downloaded here https://www.mediafire.com/?f0n0grifi7m5ccg

Comment
Add comment · Show 5
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 tanoshimi · Aug 06, 2014 at 06:56 PM 0
Share
  1. If this is a 2d game, why are you using Vector3s?

avatar image Ronin6 · Aug 06, 2014 at 07:07 PM 0
Share

Im not sure why your tank isnt rotating when you press d but in Unity its much better to use Input.GetAxis ins$$anonymous$$d of Get$$anonymous$$ey. This gives better support for multiple devices and gamepads and also gives the player the choice to customize their buttons. By default the vertical and horizontal axis are set to WASD and the arrow keys. You could say

 transform.Translate(new Vector3(Input.GetAxis("Vertical") * time.deltaTime,0,0)

and that one line of code would take care of both the W and D keys

With Question 2 I would try looking into layer based collision detection which is easy to set up http://docs.unity3d.com/$$anonymous$$anual/LayerBasedCollision.html

avatar image Sipi2000 · Aug 07, 2014 at 07:46 AM 0
Share

Comment #1 I am using vector3 ins$$anonymous$$d of vector2 cuz it's a top down game and the tank is rotating along the Z axis.

Comment #2 Thanks i'll take a look at it.

avatar image Kiwasi · Aug 10, 2014 at 07:56 PM 0
Share

Don't delete questions that are solved, please leave posted so others can learn from the answer. It's the least you can do in return for the free support.

avatar image tanoshimi · Aug 10, 2014 at 07:56 PM 0
Share

@Bored$$anonymous$$ormon - I tried to do that rollback to the question earlier but couldn't - how did you do it?!

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Pyrian · Aug 07, 2014 at 11:10 PM

  1. Your code for "D" should probably use rotate like it does for "A" instead of Translate like it's using in your code snippet.

  2. I don't know, but are you absolutely sure that Hull is set correctly in these clones?

  3. I can't tell from this what's killing your tank, but I'm pretty sure your negative Z-value is coming from the Translate in issue #1...

Comment
Add comment · Share
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
0

Answer by Foose · Aug 10, 2014 at 08:13 PM

I just googled "unity Tank 2d movement script" and google gave me this tutorial. I guess thats pretty much what you are looking for ;) http://wiki.unity3d.com/index.php/SimpleTankController

Comment
Add comment · Share
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

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

8 People are following this question.

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

Related Questions

Enemy Knockback when hit player 2D Topdown 1 Answer

2D camera zoom smoothing and limitations? 1 Answer

Echolocation in 2D top down game 0 Answers

Multiple Cars not working 1 Answer

Can't make object follow mouse cursor position. 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