playMaker

Author Topic: How to get inpact vector? [SOLVED]  (Read 208 times)

Krillan87

  • Junior Playmaker
  • **
  • Posts: 62
    • View Profile
How to get inpact vector? [SOLVED]
« on: October 31, 2017, 04:55:01 AM »
Hi,

I have a simple question that I, for some reason, are not able to solve.

So I have 2 characters in my multiplayer scene. 1 warrior with an axe and one Wizard that shoots fireballs.

Now I just wanted to add a feature that the warrior could swing his axe at the incoming fireball to bounce them back (Like a tennis racket).

My approach was to use the "Get collision info" when the fireball hit the object with tag "axe". In the collision info I use the normal to calculate the incoming vector and spawn a new "bounce fireball" that shoots back at the same angle as the incoming fireball hit. But I guess I need to modify the normal vector on some way?

The problem is that I can't manged to set the correct angel/flypath of the bounce fireball, it's always the same angel. My conclusion is that I do not really understand what is meant by "contact normal". Can someone please help me with this simple(?) problem.

Some info:
The fireball is a PArticle system with a sphere collider and rigidbody.
The incoming fireball has a fixed speed that sets at the instantiation of the fireball and do not rely on gravity or world physics.
« Last Edit: November 07, 2017, 08:20:38 AM by djaydino »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2280
    • View Profile
    • jinxtergames
Re: How to get inpact vector?
« Reply #1 on: October 31, 2017, 01:25:05 PM »
Hi,
Try this :

In the info use Relative Velocity.

Then use a Vector3 Operator.

in 'Vector 1' use the Relative Velocity result
in "Vector 2' Set x -1 y -1 z -1
then use set velocity to set the velocity from the fireball (which you can get in the collision event)

Krillan87

  • Junior Playmaker
  • **
  • Posts: 62
    • View Profile
Re: How to get inpact vector?
« Reply #2 on: November 01, 2017, 03:53:48 AM »
Hi,
Try this :

In the info use Relative Velocity.

Then use a Vector3 Operator.

in 'Vector 1' use the Relative Velocity result
in "Vector 2' Set x -1 y -1 z -1
then use set velocity to set the velocity from the fireball (which you can get in the collision event)

Hi,

Thanks for the answer. I did not get it to work in the first try, gonna try more. Why should I use the relative velocity? What to I gain by that?
What operation should I use in the "Vector3 operator"? The default operation is "add".

I also want to add that when the wizard fireball hit the axe, I destroy the fireball and spawn a new one in the same contact point. But your idea seems to actually bounce the real fireball back and not instantiate a new one. IS that a better approach over all?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2280
    • View Profile
    • jinxtergames
Re: How to get inpact vector?
« Reply #3 on: November 01, 2017, 06:01:09 AM »
Hi,
Sorry i forgot to mention to set 'multiply'

I think you can use a new object, but with the particle system you might have a better effect when bounce back.

Here you can see how to set it up :


Krillan87

  • Junior Playmaker
  • **
  • Posts: 62
    • View Profile
Re: How to get inpact vector?
« Reply #4 on: November 02, 2017, 02:32:24 AM »
Hi,
Sorry i forgot to mention to set 'multiply'

I think you can use a new object, but with the particle system you might have a better effect when bounce back.

Here you can see how to set it up :



Oh wow! Thanks for the video. The result kinda works and I think that I understand your approach. The multiply by -1 is to get the inverted vector3 right?.

However, the result is a bit random I feel, and I do not really understand why. The relative velocity is always 0.0.0. Is that because one object is not moving?

I should also not that the incoming fireball use a "move to" with a raycast and do not rely on velocity to move. This is because the game is in 3rd person. Look at this video, the bouncing fireball feels a bit random. (tbh. I do not even understand WHY not all just goes to the same place because the velocity i 0,0,0)

I made a video:
https://christiane.tinytake.com/sf/MjA4MTAzMV82NTMzOTY4

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2280
    • View Profile
    • jinxtergames
Re: How to get inpact vector?
« Reply #5 on: November 02, 2017, 02:31:28 PM »
Hi,
Do you want it to bounce back to the wizard or bounce off the wall like if you would throw a ball to the wall?

i can't test at the moment but
if the 2nd one i would create a 'physics material' and place it on the fireball collider
on the 'material'
You can play around with the friction and stuff, but you can start by setting static friction to 0 and Bounciness to 1

and use a 'look at' and then a 'set velocity' or 'add force' (space set to 'self' and i think in Z direction)


Krillan87

  • Junior Playmaker
  • **
  • Posts: 62
    • View Profile
Re: How to get inpact vector?
« Reply #6 on: November 06, 2017, 05:29:38 AM »
Hi,
Do you want it to bounce back to the wizard or bounce off the wall like if you would throw a ball to the wall?

i can't test at the moment but
if the 2nd one i would create a 'physics material' and place it on the fireball collider
on the 'material'
You can play around with the friction and stuff, but you can start by setting static friction to 0 and Bounciness to 1

and use a 'look at' and then a 'set velocity' or 'add force' (space set to 'self' and i think in Z direction)

Alright, I think got a pretty good result now. I ended up with the bounce-material thing. And instead of "move towards" I use the "look at" and "add force"

Thank you so much for your help. I have another small issue now that I just can ask when we already are talking about it.

So, right now I have 2 colliders on the axe. 1 collider that's handling the physics (the bounce mateiral) and one that have "is trigger" to detect if the actual axe swing hit the wizard and should deal damage.

What is the best practise to go about having 2 colliders on one object? Right now, I have a child that has just a the physics-collider on it that i just a bit smaller then the trigger collider.

The problem with that solution is that the physic-collider needs to be smaller than the trigger-collider, and I would not like that way.

My gut feeling says that I should somehow work with layers here, but I never used them before so I'm not really sure how they work.

You have any input here?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2280
    • View Profile
    • jinxtergames
Re: How to get inpact vector?
« Reply #7 on: November 06, 2017, 09:56:24 AM »
Hi,
You can use tags and you can add a 2nd collider on the same object and set as trigger.
on your trigger event set a tag for the wizard (called enemy or wizard for example  :) ).
now the trigger will only trigger on that tag.

You can set multiple trigger events in a single state if you need to check multiple tags.

If you are using tags already and you can't use them for the trigger, then you can get the custom action "trigger event by layer" on the Ecosystem
this works similar as tags.

Krillan87

  • Junior Playmaker
  • **
  • Posts: 62
    • View Profile
Re: How to get inpact vector?
« Reply #8 on: November 07, 2017, 02:42:37 AM »
Hi,
You can use tags and you can add a 2nd collider on the same object and set as trigger.
on your trigger event set a tag for the wizard (called enemy or wizard for example  :) ).
now the trigger will only trigger on that tag.

You can set multiple trigger events in a single state if you need to check multiple tags.

If you are using tags already and you can't use them for the trigger, then you can get the custom action "trigger event by layer" on the Ecosystem
this works similar as tags.

Hmm...maybe i should do some work with tags to get it to work. But the main issue is the size of the colliers. If the collider with bounce-material is bigger than the collider with trigger, the fireball will never reach the trigger-collider because it will hit the bounce-collider first and just bounce away :(

The other issue is that when the axe hits the wizard and there is a collider with a material on the axe, it will push the wizard away because the collider on the axe will hit the character controller...

Krillan87

  • Junior Playmaker
  • **
  • Posts: 62
    • View Profile
Re: How to get inpact vector?
« Reply #9 on: November 07, 2017, 03:00:43 AM »
Hi,
You can use tags and you can add a 2nd collider on the same object and set as trigger.
on your trigger event set a tag for the wizard (called enemy or wizard for example  :) ).
now the trigger will only trigger on that tag.

You can set multiple trigger events in a single state if you need to check multiple tags.

If you are using tags already and you can't use them for the trigger, then you can get the custom action "trigger event by layer" on the Ecosystem
this works similar as tags.

Alright, I think I got everything to work now. I just made two layers. One "Player" and one "Bounce". And set upÄ the correct interaction in the physics-mangers.

Thank you for all your help and dedication, can't thank you enough!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2280
    • View Profile
    • jinxtergames
Re: How to get inpact vector?
« Reply #10 on: November 07, 2017, 08:20:24 AM »
Hi,
No problem, happy to help