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
0
Question by nugget_bram · Dec 05, 2011 at 10:06 AM · shooterdownbotstopangry

Top Down Shooter Help

I am a complete noob at actual coding etc with Unity, and I cant seem to find a sustainable place to learn it.

Anyway, I was wondering, (for example the AngryBots demo) how would i convert that to android controls?

One joystick to move, and one to aim + shoot while it is held.

Can someone help, or maybe come up with a prefab or something? :)

Thanks

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by IRetrograde · Dec 05, 2011 at 03:56 PM

I'm having a hard time understanding what you actually need, but I'm gonna give you a bunch of information that will hopefully get you in the right direction.

Are you trying to modify the demo to do something or do you want to create your own game with a dual analogue stick?

The best thing that I can recommend is that you learn how to script. It's not gonna be easy, but it will be super rewarding. Be happy, Unity 3d is a great place to start.

I'm gonna make a long recommendation, but I can guarantee you a few moments of "ah" and "ohhh" if you spend 1 hour on it and also read the documentation.

Also, there are a TON of great video tutorials on youtube. These can be a bit slow to sit through, but you'll learn.

1 - A good, focused start - Prime 31's UIToolkit

The best place for you to start looking at some simple demos of how some of this stuff works is to look at Prime 31's UIToolkit which you can use for Free with Unity Basic. It has great demos and documentation, take your time and read it. Gather some Star Wars inspiration and give yourself time and patience. (Prime 31's Cross-Platform UI Toolkit)

I'm not familiar with the Angry Bots demo but the following 7 steps will give you a basic top down shooter:

  1. The UI ToolkIt will give you the project and the analogue sticks on the Android to start with.

  2. Create a box on the screen

  3. Make the left joystick move the box's position on the screen on the X & Y axis

  4. Make the right joystick face the box in the direction that the right joystick is pressing

  5. Now create a projectile in front of the box (you need the position and direction/forward vector to do that)

  6. Add velocity to the projectile (use the direction of the box to direct the projectile)

  7. You now have a 2d-ish top down shooter

    2 - Download it, unzip it and open up a scene called Joystick Manager.

In this scene, you'll be able to find a dual joystick input system. If you were to build this on Android, it should work. This will show you how to read the input, how to get the sprites on the screen and since it has a lot of documentation, you can actually learn a little bit of scripting and how it all works.

I really recommend this library to learn many things.

3 - Pseudo Code & Logic to move, face direction & shoot projectile.

Now if you want to look at a bit of scripting. I'll give you a bit of fake-code (pseudo code) approach to it. The joystick demo already gives you the analogue sticks current position relative to the center of where they should be.

This basically means that the UIToolkit gives you the exact direction (vector) in which your character has to move and shoot. With a little bit of logic in there, this is how simple it could be (I'm over declaring variables so that it becomes a bit easier to read).

 void Update( float  deltaTime ) {
     Vector3 movementDirectionVector = leftJoystick.position; // Making it clear. Left Joystick = MOVE
     Vector3 weaponFireDirectionVector = rightJoystick.position; // Making it clear. Right Joystick = FIRE

     // We move the player by a little bit each frame (deltaTime)
     Vector3 thisFrameMovementOffset = ( movementDirectionVector * playerSpeed * deltaTime );
     // new player position = current player position + offset
     Vector3 newPlayerPosition = playerObject.transform.position + thisFrameMovementOffset;  
     //You'd add a lot more logic here to make this more smooth and interesting.
     playerObject.transform.position = newPlayerPosition;

     // make the rotation of the player object be the angle of the direction vector
     // This probably isn't correct (I haven't messed around too much with rotations and quaternions in Unity), 
     // do a search on google on how to get an angle from a directional vector
     playerObject.Transform.rotation = new Quaternion(weaponFireDirectionVector);

     // weapon fire cooldown has to decrease somewhere
     weaponFireTimer -= deltaTime;
     // If the cooldown has reached 0.0 then the weapon can fire again
     if( weaponFireTimer <= 0.0f ) {
           // spawn the projectile
           // the projectile should be a prefab with a rigid body with no drag and various other things
           Projectile projectile = new Projectile();
           // tell projectile to be in front of where the box is facing
           projectile.transform.position = playerObject.transform.position + (playerObject.transform.forwardVector * distance);
           // make the rigid body of the projectile have the right velocity
           projectile.rigidBody.velocity = playerObject.transform.forwardVector * projectileSpeed;

           // let's make sure that the weapon takes a certain amount of time to fire again
           weaponFireTimer = 0.25f;
     }
 }

4 - If this makes no sense to you. Please:

  1. Download the library

  2. Unzip it

  3. Run the scene

  4. Play with it

  5. Look at the code

You can learn & do this.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Top down camera player rotating 1 Answer

How To Get Object To Aim at Mouse in Top Down 3D Shooter 4 Answers

Error on photon 0 Answers

C# LookAt Mouse 2D 2 Answers

See Through Objects in Top Down Shooter 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