[5SD033]Blog 1 – The Harpoon
By: Martin Carlsson Group: 10 The Harpoon
Our main characters weapon, a mighty harpoon usually used for whaling, now used by the captain to survive in the scary waters he’s been put in. In the original concept, the harpoon was gun fired. However, to reinforce the idea that our captain is very strong, he instead throws it. Another major change from the original concept is that he only has one harpoon, and it’s attached by a rope. The rope is used to retrieve the harpoon after each throw. Making the harpoon a permanent companion made me a little more attached to it. No longer do I have to worry about getting new ammunition, I have my harpoon and it comes with me wherever I go. Throwing![]() The harpoon is aimed using a mouse cursor. Which is pretty easy to implement. What you need is to find the angle between the cursor and the starting position, you then want to normalize the angle so that your projectile travels a part of the way each update. Then you simply multiply your normalized angle with your speed and set your velocity to the results. Now talking about speed. It would be very handy if you as a player could choose how long you wanted to throw the harpoon, seeing as there are situations where you don’t need to throw it at its max radius. Wouldn’t it then be better to trade the longer radius for a quicker reload time? Wind up mechanics are very easy to implement. The way I do it is using two steps: If the player presses mouse button left, I set a timer which keeps track of how long the button is pressed. If the player releases mouse button left, set the speed to whatever constant you want and multiply with the time the player held the button down. (In my case I also have a limit of a 2 seconds wind up time)
Sprite Rotation If you’re aiming with the mouse, you already have the angle you need to work out the rotation, it might be in radians but that’s very easy to convert. In my case I needed the shape to rotate around its own axis, so I had to set the origin to the middle of the sprite. ![]() Now, underwater physics are pretty interesting. To throw something underwater is very hard, as the density in water is much higher than in the air. Obviously simulating that wouldn’t be very fun(cause the harpoon wouldn’t go anywhere). But something which does add depth to the mechanic is deceleration, the drag force underwater is pretty high and deceleration should be pretty substantial. The general idea with deceleration is, you want to keep the normalized angle you got from your mouse aiming and then decrement the speed constant. That way, your projectile will still move towards the target, but will slow down along the way. And that pretty much covers the movement of our Harpoon. Thanks for reading!
|




