• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
Question by joseques · Feb 23, 2014 at 10:13 AM · dragsystemshootmanagerand

Drag and shoot system

Hi! First of all, my native language it's spanish, so I will try to explain my problem the best I can. Going to the problem: I need help, trying to make a Shooting manager script, but I'm not talking about FPS shooting like. I talk about making a drag and shoot script (Like Angry Birds, you know). I already have scripts for the job, but the problem is they are splitted in two scripts. One for the drag and shoot action and one for the camera (follow the shooted projectile). I need to combine this two scripts in one but the problem is to load another projectile for the next shoot while the camera its following the projectile, I have any problems to assign them in the inspector, I only want to get an idea to see how I can make this script (Or combine the two scripts that already have).

If anybody can understand I'll explain how my drag and shoot system works.

DnS.cs -- In this script I have the shooting system, detect the mouse clicks, calculates the ammount of force, etc CameraFollower.cs -- This script controls the camera with a simple condition. if shooted { follow projectile }

I'm not making a "Can you do this script for me?" answer, I only want opinions so I can clear my ideas and make my Drag n' shoot system.

Comment

People who like this

0 Show 4
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 joseques · Feb 23, 2014 at 06:09 PM 0
Share

Well, I think nobody have ideas. I'll keep trying to do this, if I can't do it I'll research some alike scripts

avatar image KiraSensei · Feb 23, 2014 at 06:12 PM 0
Share

I can't access the scripts, so I can't help you merging them into one script.

avatar image joseques · Feb 23, 2014 at 06:44 PM 0
Share

http://snipplr.com/view/73726/camerafollowercs/

http://snipplr.com/view/73727/dnscs/

Here are the scripts

avatar image joseques · Feb 23, 2014 at 06:53 PM 0
Share

Remember that I want to merge them in one, but I want to use the concept of state machines like the answer of aurelioprovedo , but loading another projectile while the camera its following the actual shooted projectile

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by aurelioprovedo · Feb 23, 2014 at 06:31 PM

I would use the concept of state machines for this one. The camera should have an enum variable that defines what the camera is doing at a given time. The different states (the values for that enum) could be the following:

  • Idle: the camera shows the scenario or the player before it starts the shot. You should use a public variable of type Transform for specifying the transform that the camera should look at (for example, 'targetPlayer').

  • Aiming: the camera focuses on the player/slingshot/weapon/whatever while it is aiming the shot. You could add a zoom in/out depending on the future strength of the shot.

  • Follow Shot: follow the projectile. When setting this state, you need to specify the actual projectile by setting a public variable in the script (for example, 'currentProjectile').

  • Back to idle: the camera does a travelling from the 'currentProjectile' to the 'playerTarget'. Once the travelling ends, you change the camera state to 'Idle' or 'Aiming', depending on the state of the input.

Of course, you need to use smooth camera movement to change from one state to the other.

Si no entiendes algo en inglés, dímelo y te contesto en español.

Comment
joseques

People who like this

1 Show 6 · 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 joseques · Feb 23, 2014 at 06:44 PM 0
Share

I've already using states, but I dont understand how to switch between these states.

avatar image joseques · Feb 23, 2014 at 06:46 PM 0
Share

The camera it's not the problem indeed, the problem it's load the projectile while the camera it's following the already shooted projectile

avatar image aurelioprovedo · Feb 23, 2014 at 06:59 PM 1
Share

I've checked your code and you are not using states. At least, not correctly.

You are depending on the Input in order to choose the state that you are currently on. That's not the way to do it. You need to keep a variable that tells you the current state. And then, change from one state to the other by reacting to events.

Of course, you will check the current state in the Update function and perform according to that state. For example:

 if (myState==DnSCameraStates.Idle) { //Show the entire level statically, focusing on 'targetPlayer' }
 else if (myState==DnSCameraStates.Aiming) { //Zoom in/out showing the level while focusing on 'targetPlayer' }
 else if (myState==DnSCameraStates.FollowProjectile) { //Update 'transform.position' to follow the 'currentProjectile.position' }
 else if (myState==DnSCameraStates.BackToIdle) { //Smoothly move towards 'targetPlayer', and once you are done, change the state to 'Idle' or 'Aiming' }


I don't see in the code that you are alerting the camera of a new projectile being loaded. Are you?

avatar image joseques · Feb 23, 2014 at 07:08 PM 0
Share

Oh, I understand your point. I'will try it when I'm at home and if it works I will mark your ansewer as correct. Thank you very much.

One last question, It can be a switch instead of an if statement ? Only asking, it's not relative to my original question.

avatar image joseques · Feb 23, 2014 at 11:36 PM 1
Share

It works like a charm. I'll mark as correct and I'm going to improve my script.

Gracias y saludos desde Argentina!

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Accessing local system ( File Browser ) 2 Answers

Manager System Usage example needed 1 Answer

Collision detection and battle management for action game 1 Answer

ball shooting passing through 1 Answer

Help starting a card app 0 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