Skip to content

Add 3d arrow projectiles#980

Merged
Interkarma merged 1 commit intoInterkarma:arrowsfrom
Allofich:arrows
Oct 31, 2018
Merged

Add 3d arrow projectiles#980
Interkarma merged 1 commit intoInterkarma:arrowsfrom
Allofich:arrows

Conversation

@Allofich
Copy link
Copy Markdown
Contributor

@Allofich Allofich commented Oct 25, 2018

This replaces the temporary instant arrow hits with actual 3d projectiles.

This is probably messier than it should be, as I put it together with trial and error. For example, I couldn't use the existing collider used by DaggerfallMissile, because it won't work with the concave shape and I had to make the rigidBody kinematic. Instead I use a sphere ray cast for the arrows. Interkarma, please feel free to gut this implementation if you don't like it. Functionally, it works, though.

All existing arrow code was adapted to work with it. I had to account for various things, like getting the player weapon at the time of shooting, not the time of damage calculation, since they might unequip their bow before an arrow hits the target.

Known issues:

  • The arrow hit sound plays without any doppler because the same code as it used for spell projectiles is used, and they aren't using doppler. (Seems to me like they should, even if classic doesn't)

  • When looking up or down while shooting an arrow, the arrow spawns offset from the center of the screen where it should spawn from.

  • There is a merge conflict with the Serializable enemy prefab in the AI combat PR, which will need to be fixed. I can update the PR as needed or you could do it yourself if you want to.

  • The arrows can sometimes displace enemies or the player a little bit, I think because of collision with the 3d.

@ajrb
Copy link
Copy Markdown
Collaborator

ajrb commented Oct 25, 2018

Is this an update over classic? Or are arrows actual projectiles in classic then? I assumed not because arrows that don't hit a target are lost.

@Allofich
Copy link
Copy Markdown
Contributor Author

They are in classic, it's just hard to see them because of the low screen resolution. Do a frame-by-frame in a well-lit area like a castle throne room and you'll see them.

@Allofich
Copy link
Copy Markdown
Contributor Author

Tweaked the position of the arrow a bit (it closely matches the sprite when shooting with a level view now) and slightly slowed the arrows as they were a little too hard to see.

@Allofich Allofich force-pushed the arrows branch 3 times, most recently from 912249f to e47389c Compare October 25, 2018 14:56
@Allofich
Copy link
Copy Markdown
Contributor Author

Made arrow impact use doppler.

@Interkarma
Copy link
Copy Markdown
Owner

Interkarma commented Oct 25, 2018

The arrow hit sound plays without any doppler because the same code as it used for spell projectiles is used, and they aren't using doppler. (Seems to me like they should, even if classic doesn't)

I started with doppler for spell missiles and removed it because it just made spells sound weak and ineffective at range. It may not be "realistic", but removing doppler makes them feel punchier and more energetic on impact. They're much more satisfying without.

For example, I couldn't use the existing collider used by DaggerfallMissile, because it won't work with the concave shape and I had to make the rigidBody kinematic

If you use a BoxCollider, Unity should create a minimum fitting box around the projectile. If you want to make collisions a bit more generous, you could manually add a box collider and tweak dimensions to where happy. It should be fine as kinematic, provided it's not marked as a trigger. I had to change this earlier when I learned the hard way that triggers use their own different physic implementation and may not be reliable in complex trigger-to-mesh environments.

@Interkarma
Copy link
Copy Markdown
Owner

Good job on this, it looks fine on a read. I'll play with it when I can and offer any feedback. Thanks for putting all this together! 👍

@Allofich
Copy link
Copy Markdown
Contributor Author

Allofich commented Oct 26, 2018

If you use a BoxCollider, Unity should create a minimum fitting box around the projectile.

I tried using a BoxCollider instead of a SphereCollider, assuming that's what you mean, but the error still happens.

Non-convex MeshCollider with non-kinematic Rigidbody is no longer supported in Unity 5.
If you want to use a non-convex mesh either make the Rigidbody kinematic or remove the Rigidbody component.

Seems like the problem is with the Rigidbody component, not the collider type.

This isn't a blocker for me. Hopefully using a better physics solution would solve the problem with the arrows sometimes pushing the entity (player or enemy) when they collide, but I don't know that it would.

@Interkarma
Copy link
Copy Markdown
Owner

I tried using a BoxCollider instead of a SphereCollider, assuming that's what you mean, but the error still happens.

Can you explain what the error you're encountering is exactly? I'm not really clear on the problem you encountered. I'll try to help if I can. :)

@Allofich
Copy link
Copy Markdown
Contributor Author

I quoted it, the message starting with "Non-convex MeshCollider"

Same as with the SphereCollider, if I make the Rigidbody have "Is Kinematic" checked, the error won't appear, but OnCollisionEnter() in DaggerfallMissile.cs doesn't fire. That's why I looked for another solution and used Physics.SphereCast.

@Interkarma
Copy link
Copy Markdown
Owner

Apart from easy 3D model helpers, the missile class was written from the start to support arrows - any kind of missile in fact. Its missile agnostic. All the collision handling you need is already in there for you. Either a SphereCollider or BoxCollider will be fine.

I'll add an example for you when I can over weekend and we can rework PR from there. :)

// Offset up so it comes from where it looks like it should from on the enemy sprites
if (caster != GameManager.Instance.PlayerEntityBehaviour)
adjust = new Vector3(0, 0.6f, 0);
else // Offset forward to avoid collision with player and to the right to match bow animation
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember there's an option to switch weapons to left hand.. looks wierd with a bow but is possible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixing it now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is fine, as that option just draws the weapon to the left, but bows are still equipped in the right hand. But the arrow won't spawn in the right place, so I have to fix that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the arrows to appear correctly when this option is on.

@Interkarma Interkarma changed the base branch from master to arrows October 26, 2018 13:07
@Interkarma
Copy link
Copy Markdown
Owner

I'll send this to an "arrows" branch on my side and we can collab on it. Let me know when you're clear and tag me in. I'm going to revert some of the changes to the missile class if that's OK. It shouldn't need many changes at all to support arrows as the missile class doesn't care what kind of missile it is. Even the 3D arrow can be done through composition (i.e. add another component to missile prefab for arrow itself) rather than modify the missile class directly.

Anyway, I've got to get some sleep. Will help out more over weekend as I can. This is the first weekend in a while I haven't been working and my other half has organised some social events for us I've promised to be available for. :)

@Allofich
Copy link
Copy Markdown
Contributor Author

I'm done with it for now.

I'm going to revert some of the changes to the missile class

Go ahead!

@Allofich
Copy link
Copy Markdown
Contributor Author

Allofich commented Oct 26, 2018

I'll send this to an "arrows" branch on my side

I see that branch already exists, so I'll re-target it to that.
Edit: Nevermind, I guess you already changed it or something, because it's already pointed there.

@ajrb
Copy link
Copy Markdown
Collaborator

ajrb commented Oct 27, 2018

Anyway, I've got to get some sleep. Will help out more over weekend as I can. This is the first weekend in a while I haven't been working and my other half has organised some social events for us I've promised to be available for. :)

Enjoy and relax mate - DFU stuff can wait.

@Interkarma
Copy link
Copy Markdown
Owner

Edit: Nevermind, I guess you already changed it or something, because it's already pointed there.

I did, sorry I forgot to mention. I just wanted to make sure you were clear before merging.

Enjoy and relax mate - DFU stuff can wait.

I ended up having a great weekend. Good to feel less under pressure again for once. :) Didn't quite get those builds out, but taking care of that this morning.

@ajrb
Copy link
Copy Markdown
Collaborator

ajrb commented Oct 29, 2018

Enjoy and relax mate - DFU stuff can wait.

I ended up having a great weekend. Good to feel less under pressure again for once. :) Didn't quite get those builds out, but taking care of that this morning.

Very glad to hear it. You have to pace yourself man, this is a marathon not a sprint... and we would all be screwed if you burn yaself out!

@Interkarma Interkarma merged commit ed05d79 into Interkarma:arrows Oct 31, 2018
@Allofich Allofich deleted the arrows branch October 31, 2018 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants