playMaker

Author Topic: Push Enemy on Collision  (Read 246 times)

heavygunner

  • Full Member
  • ***
  • Posts: 145
    • View Profile
Push Enemy on Collision
« on: January 27, 2019, 06:03:09 PM »
Hi !

I wanna push the enemy when I hit him.
I have 2 Cubes. One me and another Navmesh agent. When every time I collide with him, he should be pushed to a cert in distance.

Case 1 : if he come towards and hit me, he should pushed back.
case 2: if he running and I chase him. When I hit that time, He should pushed forward .

How can do it ?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14121
  • Official Playmaker Support
    • View Profile
Re: Push Enemy on Collision
« Reply #1 on: January 28, 2019, 02:04:25 AM »
Hi,

 you need to listen to collision using the global system event ON COLLISION ENTER

then you use GetCollisionInfos and get the normal of the point of contact.
you use this normal as the direction of the force you will add to the ennemy for it to be pushed back.

 have a go, and let me know where you get stuck in the process.

Bye,

 Jean

heavygunner

  • Full Member
  • ***
  • Posts: 145
    • View Profile
Re: Push Enemy on Collision
« Reply #2 on: January 28, 2019, 12:58:56 PM »
I added Force to Player. I bumped up. Still have no idea where to add Add Force and in which axis. Tried many combinations. No luck so far.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14121
  • Official Playmaker Support
    • View Profile
Re: Push Enemy on Collision
« Reply #3 on: January 29, 2019, 01:29:39 AM »
Hi,

ok, two things:

- the property AtPosition is a point in space, not the direction, so this should be the contact point that you fill in from the collision infos, not the normal.

 - you add 0 as the force. the Vector property should be the normal vector ( multiplied with a force amount, as the normal vector has a magnitude of 1 which is not enough to imply any kind of movement to a physic object.

Bye,

 Jean

 you've define