Harpoon Gun

My game requires a harpoon gun. Problem is, I have no clue where to start. The game is a sidescroller so I haven’t found much support for this. Basically, the harpoon gun needs to rotate and always be facing the reticule, which is controlled by the mouse. You need to be able to fire it obviously. Any tips and pointer,s or even a base code would be awesome.

Here’s a screen.

What does it need to do? Fire out in a single direction, potentially hit something then be wound back in?

Also tho when you say you dont know where to start… What level is your programming?

I made a physics based movement script for the character you see on scree, he moves in all directions with the current of the water and gravity level. It’s just single fire, but doesn’t come back in.

Why a harpoon?
Why not just a projectile?
Is it the teather factor that you need.
If so can it just be an animation?
If so, perhaps you can sprout a sinewave like object from the projectile.

:.?

Edit.
Or better yet. Why not make an object, which would be a greyed out single pixel (to keep with the games style). Fire the projectile say along x. Create 2 pixels (ropePixel) place one as the player base dot and the other as the harpoon base. Then as the harpoon travels along, one pixel at a time, place a ropePixel in. First on pixel one unit in and one unit up, then two by two etc alll the way to the point where you would create a sine wave.

:. This would keep the visual consistency of you 8 bit game.

It would require that each ropePixel placed in, always keep it position relative to either the harpoon base or player base pixel and as each movement of one pixel distance, that one ropePixel be placed in position.

That doesn’t tell em how to really code it, or where to start. As for your comment I was thinking maybe an udnerwater type of gun that when used it let out a stream of bubbles, kinda like in a railgun fashion, it just used force comign out the barrel. But I’d just like to know how to code my Harpoon gun. The harpoo is only a projectile arrow.
Theres no tether or anythign attached.

You could approach this a number of ways. Offhand, your arm+harpoon would be parented to your player gameobject, with a transform.LookAt(cursor xy) constraint. This would handle the aiming at the cursor bit.

For the projectile, you might create a prefab that consists of the projectile sprite, collider, rigidbody component, and a particle system that would handle the bubble spawning. You’d then instantiate the prefab at the harpoon’s muzzle location, match rotation, and give it a velocity (rigidbody.velocity).

And the bubbles would float up? In a trail?

In that case look at …

Yield WaitForSeconds

InvokeRepeating

And Instantiate or object pool.

I see what you guys mean. I could definatley do that. Now how would I start the code.

um,
if you do not know how to even start, i would suggest you learn basic coding first. because if i tell you this, you will ask me how to to do that and that and that.

but!
since its chistmas and I cant leave my computer to do the chores right now…

you would want somthing like this.

function fireHarpoon()
{
harpoon.moveThatWay();
InvokeRepeating(“placeBubble”, 0.1, 1=0.5);
}
what that does is fire your harpoon. (of course you will have to figure that out (there are many different ways to move an object in Unity.
Then, it invokes a repeating of the funtion placeBubble().

function placeBubble()
{
bubble = instatiate(bubblePRefabe, harppin.transform.position, harpoon, transform.rotation);
bubble.floatUpToSerface();
}

God luck holmes. I got to do chores and You got to learn how to code.

thank you, i knwo absic code but just never made a gun before

Surely if you were able to make a “physics based movement script” you could programme your harpoon to act under gravity in the same way your character does?

Its actually really simple tho.

rigidbody.AddForce (0,0,0));

And I just put these underneath an if button is up/down/etc.
I shall try tho.