playMaker

Author Topic: bullet help [SOLVED]  (Read 5311 times)

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
bullet help [SOLVED]
« on: October 23, 2019, 04:50:30 AM »
I am looking for help with my current setup when shooting.

No matter what I do I cannot at the moment get the bullet to accurately move towards the cross hair target.

Each weapon is a child of the main character, with each having there own bullet spawn point and a cross hair target.

When you shoot the bullet is spawned and force is used to make it go forwards, however the target and bullet has issues with not lining up.

The target is a 2d sprite and I moved this forwards into position, but the bullet will miss the location entirely sometimes.

Thankyou for your time and help

You can download the original files here:   

https://hutonggames.com/playmakerforum/index.php?topic=20555.msg90096#msg90096
« Last Edit: October 30, 2019, 07:14:27 PM by colpolstudios »

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: bullet help
« Reply #1 on: October 23, 2019, 08:44:47 AM »
OK so first think about this: The crosshair is generally NOT where the bullet is spawned from. It's also generally not in the same orientation of the gun. An FPS character firing from the hip has the gun at the bottom right or left of the screen, where as the crosshair is in the middle.

Now you have considered that the different lines of orientation have to line up. Think about how this would work. If you shine two lasers next to each other, then rotate one to meet the beam of the other, they will only ever cross paths at 1 exact distance from you. This means your crosshair will only work at one exact distance if you simply try to rotate your fire point to intersect with the crosshair orientation.

I have resolved this using this method:

* Ray cast from the center of the crosshair position. This will create a point in space at the exact distance your first wall/object is in the way. Store this position

* Have your gun spawn position rotate to look at this stored position. This is your range finding system so it's never looking too close nor too far.

* When you spawn your projectile, set it's rotation to match you object looking at the stored position.

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: bullet help
« Reply #2 on: October 23, 2019, 03:34:05 PM »
But what happens if i target the sky?

I would also need a non hit.

How do I allow for this?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: bullet help
« Reply #3 on: October 23, 2019, 06:56:51 PM »
Hi.
you can add a finished event and set Repeat interval to 0 (so it will only raycast 1 time and not every frame (or every x frames)
OR
You can get Raycast2 from the Ecosystem. it has a 'no hit event'

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: bullet help
« Reply #4 on: October 23, 2019, 10:45:04 PM »
But what happens if i target the sky?

I would also need a non hit.

How do I allow for this?
Ah yes, sorry I forgot about that. That is a weak point in what would otherwise be tidy. In my last project I used this system, I actually created an invisible box to close in the scene and ensure there always was a hit.

Off the top of my head though, you could take Djaydino's tip about Raycast2, and in the event of a non hit, set your fire point to a pre-configured rotation so it intersects with your cross-hair an 'average distance' forwards from you.

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: bullet help
« Reply #5 on: October 24, 2019, 01:34:44 PM »
I am doing something wrong as the bullet when fired is acting very strangely.

Would you mind having a look at the attached images please.

1. The spawn point gets the target range type: vector 3 from the crosshair and using smooth look at rotates towards this vector 3.

2. The crosshair using raycast 2 gets the hit point. type vector 3

3. The shooting FSM at the create object point. I get the vector 3 from the crosshair and use this to rotate the spawned bullet

Thank you for your patience and help

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: bullet help
« Reply #6 on: October 24, 2019, 11:37:17 PM »
First thing I can see is that you have 'Keep Vertical' selected in Smooth Look At action.Unless I'm mistaken, this would mean that it looks in the X and Z direction of the target, but ignores the Y axis (so doesn't look up or down).Turn it off.

Second; In your 'create object' State (in 'rebelman : shooting), you have a 'Create Object' Action. The spawn point is seemingly correct (the object you rotate to look at the target) but you have set the rotation to 'range to target'. This is wrong. You should have also set it to the 'Spawn pistol' object, since that's the object which rotated to look at the target.

Just so you understand; what you are currently doing is finding out what the rotation of your target position is, and then matching to it. Not looking at it, instead you are mimicking it. By using the correction above, you are making sure the bullet mimics the direction of your spawn point, which in turn is looking at the target you got from the crosshair raycast.


colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: bullet help
« Reply #7 on: October 25, 2019, 08:45:56 AM »
I am still having the same issue with the bullet acting strangely

Would please take a look at the updated attached image thank you

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: bullet help
« Reply #8 on: October 25, 2019, 09:06:06 AM »
Hi.
I think you can get the rotation from the weapon in world space and apply that to the bullet.
but it also depends on the weapon if they point of the weapon the forward direction is.
if it is not, you could make an empty child and set the correct rotation.

Another thing also to watch out for is collision, it might be that the weapon has a collider and is not ignored by the bullet layer.

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: bullet help
« Reply #9 on: October 25, 2019, 11:23:00 AM »
I am still having the same issue with the bullet acting strangely

Would please take a look at the updated attached image thank you
This screenshot has the same error. The rotation for your created object is meant to be your bullet spawn point, after it has rotated to look at the range target. As djaydino said, get the bullet spawn point's rotation (Get Rotation action) in the world space (not local).

Also do take the other part of djaydino's advise too, and make sure you have removed the collider on your gun, or used the physics settings page to make sure the Layer you put your bullet in can't physically interact with your gun's Layer.

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: bullet help
« Reply #10 on: October 25, 2019, 04:52:12 PM »
Just to be clear the character and all of his children are set to ignore raycast.

The spawned bullet is on Default layer.

The walls, floor and enemies are also on default layer.

No collider on the weapons.

I am now using (Get Rotation action)

However I do not see any great difference the bullet still misses the croshair target.

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: bullet help
« Reply #11 on: October 26, 2019, 12:19:47 AM »
It's confusing that you would call the spawn point rotation variable the same thing as your crosshair target position variable; 'range to target'. In fact, are you not overwriting your actual range to target position variable by doing so? Start by doing yourself a favor and use a variable called 'spawn rotation' or something like that for your Get Rotation action to store to.

As a side note;

I see you have Every Frame selected for Get Rotation. This is unnecessary, so turn it off just to be tidy (and to avoid potentially the state repeating and not moving to the next, depending on if the other actions have transitions or not).




colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: bullet help
« Reply #12 on: October 29, 2019, 06:48:50 PM »
I tried something a little different.

In the IK pistol FSM at the activate IK state I added

raycast 2: from the spawn target for the pistol

distance 10

store the "hitpoint" on miss

I created a new crosshair in the hierarchy this is not a child!

Set position of this crosshair vector "hitpoint" every frame and late update.

Then in the deactivate IK state I set the position of the crosshair to out of sight.

The only thing is that when I shoot the crosshair itself moves along the line of the bullet

Edit: Ive spotted the error I am in the process of updating the shooting system to use raycast.

Thank you both for all of your valuable help



« Last Edit: October 30, 2019, 07:13:49 PM by colpolstudios »

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: bullet help [SOLVED]
« Reply #13 on: October 31, 2019, 07:39:01 PM »
I thought
daniellogin and djaydino

Might be intrested in the way I have done things?


https://simmer.io/@colpolstudios/mechanim-simple-ik-v-05


Points of interest:

variable naming.

I thought as each FSM is unique. I did not have to worry about naming issues.

However, inadvertently thinking this way helped in re-organizing my global custom events.

So now, I have custom specific events in relation to the pistol and the dual handed weapons.

I fixed some outstanding bugs.

Reloading, but would like to improve on this current method.

currently, you have to wait until the ammo runs out.

I'd like to be able to do this if any ammo was used, replacing the ammo used!

My current switching between shooting and NOT shooting has issues and will need a separate help request.

I wish to thank you both for your time and help with me.

Kind regards

colpolstudios