playMaker

Author Topic: Problems with player shooting and isn't affected by moving triggers if idle  (Read 2395 times)

Avascar

  • Playmaker Newbie
  • *
  • Posts: 45
Hello everyone, I would want to make this quick and easy, but I would like to know how to script a player shooting a bullet at the mouse cursor? Basically, when you left click your mouse somewhere in the game, the player will create a game object (prefab, bullet) and shoot it at the mouse cursor. However I'm having trouble adding somewhat a force or something to the bullet and getting the mouse cursor position. Any help?

ALSO (edit): I'm also having a bit of trouble, I have triggers that makes the player do a death script and made them move. However, if the trigger touches the player, the player doesn't affected by the trigger at all if it stays there. Is there another way to do this?
« Last Edit: November 24, 2012, 08:00:02 PM by Avascar »

Red

  • Hero Member
  • *****
  • Posts: 563
Well, I think i can answer the first question (but the second one is one i've faced as well... only workaround is to have the triggers moving somehow but that is a bit of a hack and isn't ideal.)

for the gun weapon, using a prefab can be a little tricky... it requires that you have a spawn point with which to place the bullet prefab however i've found that placing the spawn point within any existing geometry or triggers that it's not set to ignore makes the behavior go wonky... so, the solution to that is to have a spawn point (you can take an empty game-object and place it as a child to the thing which is shooting from it) and spawn from there... as for the motion, you can use the "Add force" to the object to give it movement.

now, getting it to go where you want it to go is a little tricky sometimes so for that i've used a separate object that points towards the mouse point that's selected with the "mouse pick" action. this works well with third person and even some first person scenarios... with the mouse pick, you can have the object look at the point and from there the adding of force can be done by giving it a forward momentum (the Z axis) so long as the object is spawned and oriented towards the object you want.

this should give you a good starting point... the amount of force will be different depending on the game you're making and the scale of everything... and the type of force you can play around with it. i've found that the "impulse" works well enough.

if there's anything more i can help with that i can help with, feel free to ask.

Avascar

  • Playmaker Newbie
  • *
  • Posts: 45
Thanks a lot, I was dumbfounded there for a bit! xP
And for the second solution I'll try using collisions and rigidbodies.