playMaker

Author Topic: Help with bullet ricochet using Add Force and Colliders[SOLVED]  (Read 5721 times)

BattleCat

  • Playmaker Newbie
  • *
  • Posts: 5
Help with bullet ricochet using Add Force and Colliders[SOLVED]
« on: September 27, 2013, 01:25:18 AM »
Hey guys,

I'm only a week into Playmaker and Unity so please excuse me if I'm missing something obvious.

I'm making an FPS and I would like the bullets to ricochet off the walls. My problem is that the ricochet direction is always downwards (-Y) but the Z and X seem to be correct. Eg. If I hit the wall at an upward angle I'd expect it to continue upwards. I've got a tracer on it too, and sometimes I can see the trace line wobbles after it ricochets which I have idea about either (but that's not so much a problem yet). I'm only using colliders, rigid bodies and add force to achieve this at this point, so I'm not sure if that's where the problem lies and this is harder than I thought.

This is how the sequence of events roll:

1. Mouse1 to spawn bullet object
2. Bullet uses Add Force to propel on self Z axis
3. Walls, floor and ceiling are tagged "walls" and upon Collision Enter they add 1 to a float value "ricochetCount".
4. If ricochetCount is >=1 when it hits a "wall" the bullet will destroy itself.

As far as I can tell, this all seems to be working correctly. I just can't for the life of me figure out is this problem with the upwards angle of the ricochet.

If it helps, I'm not using gravity on the bullet object, and I've put a sphere collider on it, to simplify the deflection. I've attached a screenshot.

Thanks in advance for reading this and any help you give me.
« Last Edit: October 14, 2013, 06:41:23 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Help with bullet ricochet using Add Force and Colliders
« Reply #1 on: September 27, 2013, 05:15:01 AM »
Hi,

 I would make a minimal scene, with the bullet and a cube actin as a wall. Fire the bullet at the wall and get it to work the way you want.

 if you are still having problem with that set up, let me know, I'll do a working examples.

bye,

 Jean

BattleCat

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Help with bullet ricochet using Add Force and Colliders
« Reply #2 on: September 27, 2013, 08:06:07 AM »
Hi Jean,

Thanks for the advice. I made a new scene and I've got it to work in that scene by using Add Force > Impulse (along with making the discovery of using Physics Material > Bouncy). So, I went back to my scene and used the updated prefab but saw no change in results! I even made a new bullet from scratch, but still had no luck.

I've tried manually placing a prefab bullet object in the scene (so it just flies off without the need to fire the gun) and it behaves itself. That indicates to me that something in my object hierarchy or another FSM is interfering.

What I find odd is that when using the gunfire FSM, the bullet fires correctly, in the right direction. It's only when it collides with an object that it goes to hell. I don't even have any rules set up that relevant to a collision! (RE the screenshots, everything is using the same objects/fsm, it's just the bullet creation that differs.)

There's got to be some rookie mistake I'm making here.
« Last Edit: September 27, 2013, 05:57:18 PM by BattleCat »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Help with bullet ricochet using Add Force and Colliders
« Reply #3 on: September 30, 2013, 02:02:07 AM »
Hi,

 I am not too sure what could cause your implementation to fail. Could you pm me with this example scene?

bye,

 Jean

BattleCat

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Help with bullet ricochet using Add Force and Colliders
« Reply #4 on: September 30, 2013, 07:42:24 PM »
Hi Jean,

I have no idea how, but I fixed the issue with the angles. I made all of the objects in the old scene into prefabs and made a new scene and dragged them in and it worked! Every object was the same so I have absolutely no idea why it started working. Perhaps some sort of bug?

Now I'm just trying to figure out why the bullet sometimes goes through the wall when shot straight on at a wall, but always ricochets when shot at an angle!

Thank you for your offer, Jean. Is there a specific way to package up a scene? Or can I just upload the .unity file?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Help with bullet ricochet using Add Force and Colliders
« Reply #5 on: October 01, 2013, 03:16:05 AM »
Hi,

 Packaging is better. Make sure you tick off the PlayMaker.dll file when packaging, as you it's not allowed for distribution.

 Bye,

 Jean

BattleCat

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Help with bullet ricochet using Add Force and Colliders
« Reply #6 on: October 13, 2013, 08:05:03 PM »
Sorry I didn't get back to you for so long, I didn't get a chance to get back here for a while!

I hate to ask, but I just want to make sure I'm not doing anything wrong/immoral/illegal; How do I package it for you? Is it just in the Build/Run settings? Or just zipping it up through Finder?

Thank you.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Help with bullet ricochet using Add Force and Colliders
« Reply #7 on: October 13, 2013, 08:22:18 PM »
Assets> Export Package

Uncheck any paid assets and if you're sending PlayMaker then uncheck the .dlls or either the entire Playmaker folder.

It's easier (I think) to just send the necessary assets like the materials or prefabs or scripts that you have in project view along with the scene file(s) in a unity package so the other person can simply import them into a new project or their existing one without worrying about overwriting files.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

BattleCat

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Help with bullet ricochet using Add Force and Colliders
« Reply #8 on: October 13, 2013, 08:26:22 PM »
Thank you, Lane!