playMaker

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

rongconcrx

  • Full Member
  • ***
  • Posts: 116
    • View Profile
Addforce to mouse positon?
« on: February 23, 2016, 08: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, 09:27:41 PM by rongconcrx »

rongconcrx

  • Full Member
  • ***
  • Posts: 116
    • View Profile
Re: Shooting at an angle 2d.
« Reply #1 on: February 24, 2016, 07: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

https://www.youtube.com/watch?v=eofB2Z4-00w

Ghosu

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: Addforce to mouse positon?
« Reply #2 on: February 26, 2016, 10:57:22 AM »
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.

https://youtu.be/YiT8XuVyl9k

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

Greetings
« Last Edit: February 26, 2016, 11:18:55 AM by Ghosu »