- Home /
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.
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
I can't access the scripts, so I can't help you merging them into one script.
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
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.
I've already using states, but I dont understand how to switch between these states.
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
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.Ai$$anonymous$$g) { //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 'Ai$$anonymous$$g' }
I don't see in the code that you are alerting the camera of a new projectile being loaded. Are you?
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 ins$$anonymous$$d of an if statement ? Only asking, it's not relative to my original question.
It works like a charm. I'll mark as correct and I'm going to improve my script.
Gracias y saludos desde Argentina!
Your answer
![](https://koobas.hobune.stream/wayback/20220613134429im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Collision detection and battle management for action game 1 Answer
ball shooting passing through 1 Answer
Help starting a card app 0 Answers
Accessing local system ( File Browser ) 2 Answers