playMaker

Author Topic: rayCast hit  (Read 2218 times)

mikewwayne

  • Playmaker Newbie
  • *
  • Posts: 11
rayCast hit
« on: August 04, 2013, 04:36:09 AM »
Can someone please give an example of  a gun and raycast hit?

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: rayCast hit
« Reply #1 on: August 04, 2013, 04:12:35 PM »
State 1: "get button down" action

Set up your shoot button in the input manager. I will just call it shoot for this example

When get button down detects that the shoot button has been pressed, transition into state 2

State 2:
optionally play shoot sound.

optionally create particle muzzle flare at gun

Find out the where the player is aiming (maybe using rotation from camera) and optionally add some degrees randomly to each axis to add some inaccuracy.

Raycast in the direction that you have determined using camera and random inaccuracy.

Mask the raycast to only detect 2 layers: Obstacles and Players (or enemies).

If raycast hits an obstacle, dont do anything and just transition back to state one and listen for shooting again.

If raycast hits an enemy, save the hit object as a variable, and transition to state 3

State 3:
use Send Event action

Target: your hit object variable (the enemy you hit)

Event to send: whatever you have on the enemy that makes it take HP away from itself

Then transition back to state 1 and listen for shoot button again

___________________________________________________________________

This is just a VERY basic example that should get you started. You could also add parameters to shooting like every time you shoot, rotate camera up a bit or something to simulate recoil. Anyway, this setup worked for me when i first started

Hope this helped. Good luck

-Koz
« Last Edit: August 04, 2013, 04:14:21 PM by KozTheBoss »
Remember, you don't fail unless you give up trying to succeed!