playMaker

Author Topic: 3rd Person shooter bullet direction help needed  (Read 2277 times)

JollyMan

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
3rd Person shooter bullet direction help needed
« on: November 26, 2014, 10:56:23 PM »
Hi there,
Recently I have been working on a third person shooter and have come across a substantial problem. I am trying to make my character shoot  bullets at the crosshaires (a GUI texture in the center of the screen) and I can't figure out how to give the bullets force so that they move towards the center of the screen or the crosshaires. I have tried to use ray cast from the main camera to get the direction for the bullet to travel, but I don't know how to store the direction of the ray cast even when it isn't hitting something. Any help would be greatly appreciated  :D.

Cheers,
JollyMan

cmonroy

  • Playmaker Newbie
  • *
  • Posts: 34
    • View Profile
Re: 3rd Person shooter bullet direction help needed
« Reply #1 on: November 27, 2014, 05:26:44 AM »
Since you are "shooting" always to the front of your viewport, you could try to use Vector3.forward...

The other thing is: do you really need to use bullets or would it be simpler to use the raycast to simulate a high-speed bullet?

JollyMan

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: 3rd Person shooter bullet direction help needed
« Reply #2 on: November 27, 2014, 05:48:04 PM »
Hi,
Thanks for your quick response and advice. For my game an object would be best and could you help me add force to the bullet so that it moves towards the global position that the ray cast hit?
Thanks

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: 3rd Person shooter bullet direction help needed
« Reply #3 on: December 01, 2014, 10:58:36 AM »
Couple things.

Using the raycast to detect the angle with which to fire the bullet isn't the best since raycasts afaik need to know what angle to fire off at in the first place. So, you already have either a position or an angle already.

If you have that and the reticle is smack-dab in the center of the screen, it's likely that a raycast direction of Y+ local should do it.

As for adding force... Well, that's where "Add force" will be what you'd want. For that you might want to consult the unity docs to see what kind of force you will need (I suspect "impulse" will be the one but ref the manual 1st just in case.)

http://docs.unity3d.com/Manual/PhysicsSection.html

You could I guess also have a "Set velocity" action do it too... But other than that I'm not 100% sure what would work best for your particular situation.

JollyMan

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: 3rd Person shooter bullet direction help needed
« Reply #4 on: December 01, 2014, 05:27:06 PM »
Hi,
Thanks for the reply! I mostly understand what your saying, but I don't know how to set that up. My game is all set up and only needs a few variables adjusted, but I don't know which to adjust. Would you be willing to look at my project when you get some free time and try to adjust it to work like your saying. I would be extremely appreciative! Would you try to get it working if I sent you a dropbox link of my project in a pm?

cheers,
JollyMan :)

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: 3rd Person shooter bullet direction help needed
« Reply #5 on: December 02, 2014, 04:37:55 PM »
Downloading (from the PM link) now.

I'll give it a look-see to see what's going on here.

JollyMan

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: 3rd Person shooter bullet direction help needed
« Reply #6 on: December 03, 2014, 09:26:44 PM »
Great!
Let me know if you can get it working. That would be awesome!

JollyMan

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: 3rd Person shooter bullet direction help needed
« Reply #7 on: December 04, 2014, 08:51:44 PM »
Hi,
Just wondering if the project ran correctly in unity and if you have made any progress yet. Thanks again.

JollyMan

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: 3rd Person shooter bullet direction help needed
« Reply #8 on: December 05, 2014, 12:40:49 PM »
I just opened it up recently... Err, not sure what you're trying to accomplish.

Could you repackage it with greyboxes and maybe give a bit more explanation? What I've got doesn't really make much sense since I'm missing a lot of context.

JollyMan

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: 3rd Person shooter bullet direction help needed
« Reply #9 on: December 06, 2014, 10:58:00 AM »
Hi,
Ok sorry for not giving you enough details, I can see how confusing it could be. I have sent you a PM with a fully commented out version of the actions and objects. Please read the PM to see which objects to take a look at. It also includes a link to the commented out scene. Thanks again for all your help.

Cheers,
JollyMan