playMaker

Author Topic: Addforce to mouse positon?  (Read 2121 times)

RC

  • Full Member
  • ***
  • Posts: 148
Addforce to mouse positon?
« on: February 23, 2016, 10:50:09 AM »
Hi,

How do you shoot a bullet toward your mouse  position?
I'm having trouble understanding how I would add an offset for the bullet to go toward the mouse position.

I have look at the canon game that Jean made, but it's not what I'm looking for.
Any help would be great!

Thanks
« Last Edit: February 25, 2016, 11:27:41 PM by rongconcrx »

RC

  • Full Member
  • ***
  • Posts: 148
Re: Shooting at an angle 2d.
« Reply #1 on: February 24, 2016, 09:44:54 PM »
For a better understanding of my question, I have found a youtube video of what exactly that I wanted to do. I'm sure other on here would love to learn how to do this also.

Please share your experience, Thank you


Ghosu

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Addforce to mouse positon?
« Reply #2 on: February 26, 2016, 12:57:22 PM »
One quick method i just tested:


plane (like the white background in your video) with collider set to trigger
you can delete its mesh renderer to make it invisible and translate it to the players position

FSM on your arm/hand/gun or whatever you want:
action mouse pick, store point, every frame

action smooth look at, target position: point
play around with up vector/keep vertical/speed to fit your demands or rotate you mesh/parent

... and with mouse pick event at mouse down you could simply create a bullet prefab at position gun. This prefab uses a translate, move or force action heading its lokal front position.


That's just a quick way you could tweak and build on.

Greetings
« Last Edit: February 26, 2016, 01:18:55 PM by Ghosu »