Wednesday, 14 October 2015

Improving Catapult Mechanic

Whilst the catapult worked perfectly well, a few improvements could be made to make it more efficient/rounded. My first improvement was only allowing the object to aim and jump if the mouse is clicked whilst hovering over the object. In order to do this I needed to register the mouse position upon the person clicking. I set a ray cast to fire from the camera from this point and to see if it hit the box. If so then a Boolean 'hasClicked' is set to true, else it remains false. If the Boolean is true then the player has clicked on the object so can now fire it, otherwise nothing happens.
Object with aim dots showing path

The second improvement was altering the force applied depending on how far back the mouse was dragged. So the object can perform either a large leap, small hop or anything in between. To solve this issue I was required to use a few simple projectile physics equations that determine the distance based on the velocity and gravity. Once the equations have worked out the distance travelled, the position of the dots could be adjusted to create the new flight path of the object. As all of this is in a method called within update, the path will update in real time based on how the player is angling the shot.
Physics equations applied

This way, clicking on the object and moving the mouse to aim and apply force gives the feeling of pulling something back in order to fire the object forward.

No comments:

Post a Comment