- Home /
How to create a charge attack?
I'm trying to create a charge attack similar to Reinhardt's Charge in Overwatch, but I'm not exactly sure on how I should go about it. The main things I'm having issues with is switching the cameras during the charge and how to set up a timer for the charge. Any other tips are extremely helpful.
Could you explain why you need to switch cameras in the charge? I dont play Overwatch and im thinking about the Demoman's charge in TF2 instead. It would be more helpful if you could describe the exact charging effect youre trying to create. @JediJerboa
Answer by JediJerboa · Nov 20, 2020 at 08:42 PM
@Llama_w_2Ls In game, the camera zooms out to third person to allow for better steering. Essentially, the charge is just one rocket boost forward with a slower turning speed with no way to stop other than the charge time running out or you crash into a wall. You can also "pin" enemies, where they become stuck to the player model and it also does damage to them if you collide with a wall. I really just need to figure out a way to get a model to burst forward and have difficulty turning, thus when the third person camera comes into play.
Answer by Llama_w_2Ls · Nov 21, 2020 at 07:38 AM
If your character has a rigidbody character controller, you can addforce on its transform.forward direction, to create a burst-like charge attack. To have difficulty turning, you would simply need to lower the sensitivity of your camera control. Finally, for a third person camera, change its transform.position to be a bit higher on the y, and a bit back on the z, to make it look third person.
If the character is a rigidbody controller, it should automatically stop when hitting a wall. If (like in TF2) you would want the charge to be also stopped by swinging your sword/weapon in mid-charge, you can add a counter-force in the opposite direction of the player.
Hope it helps.
You may need to change the way your movement works, if it isnt rigidbody, or you would have to simulate its effects. @JediJerboa
I see. However, the turning is also normally affected by the movement keys. I’ve had people suggest I do something with the angular velocity on the y-axis, but I’m not so sure how to write that in code.
Oh right. If your character is rigidbody, you can access its velocity properties. If you increase the drag or the mass, adding the same force will be harder. However, the angular velocity is how fast the rigidbody can rotate. You can access it whilst charging by writing rigidbody.AngularVelocity
im guessing, and set it to a new Vector3, where the y component is lower/higher so it is harder/easier to turn. I hope you figure it out.
I got it. I decided to use rigidbody.AddRelativeForce instead, and it gives the desired effect. I moved onto the camera issue, where I tried using this to change the camera's position:
GameObject.Find("$$anonymous$$ain Camera").transform.position = new Vector3(0f, 2f, -6.2f);
However, it seems to move the character along with it and not go into 3rd person (I'm guessing this has to do with the camera being a child of the player object) and I'm not sure how to toggle the camera's look sensitivity.
Your answer
Follow this Question
Related Questions
Character controller without Deltatime 1 Answer
How to rotate camera diagonally over players shoulder while still facing towards players direction 0 Answers
Should I be using time.fixedDeltaTime here? 5 Answers
How to make a sound play and have a delay after so it can't be activated again very fast? 1 Answer
MMD How to export model and animations to Unity as 3rd person controller? 2 Answers