playMaker

Author Topic: [SOLVED] Pushing enemy in correct direction  (Read 8282 times)

beaumint

  • Playmaker Newbie
  • *
  • Posts: 15
[SOLVED] Pushing enemy in correct direction
« on: October 11, 2014, 11:21:20 PM »
Hello!

I'm a new unity user and have a question.  My player uses an ability that charges forward and knocks back all the enemies they hit.  (by doing a negative translate in the direction)

So far it works great IF the enemy and the player are facing eachother.

If for some reason the enemy has their back turned to the player and they get hit they slide toward and through the player instead of being knocked away.

I know that I need to store some information from my player in order to push my enemy in the right direction but no matter what I try I can't get it to work.

Any tips for me!?
Thanks!
Drew
« Last Edit: October 16, 2014, 06:27:02 PM by beaumint »

beaumint

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Pushing enemy in correct direction
« Reply #1 on: October 11, 2014, 11:55:06 PM »
Adding a video to show what I mean in case I'm not being clear enough.
Thanks again for taking the time to help me with my problem.

Cheers!
-Drew
« Last Edit: October 12, 2014, 05:58:18 AM by beaumint »

TheBadFeeling

  • Junior Playmaker
  • **
  • Posts: 66
Re: Pushing enemy in correct direction
« Reply #2 on: October 12, 2014, 05:45:40 AM »
You video is private, so we can't see it.  ::)
3D or sprites?
The Force is with you, young Playmaker – but you are not a C# senpai yet.

beaumint

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Pushing enemy in correct direction
« Reply #3 on: October 12, 2014, 05:58:41 AM »
Oops!
Fixed it!
You should be able to view it now, and its 3d!

Thanks for the response
-Drew

TheBadFeeling

  • Junior Playmaker
  • **
  • Posts: 66
Re: Pushing enemy in correct direction
« Reply #4 on: October 13, 2014, 02:33:22 AM »
Not sure how to do that exactly, but I guess you need to figure out the direction they need to be pushed in, right? Could the Get angle to target action help?
Anyone else got any pointers?
The Force is with you, young Playmaker – but you are not a C# senpai yet.

beaumint

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Pushing enemy in correct direction
« Reply #5 on: October 13, 2014, 04:05:15 AM »
Thanks again for your reply.  I thought about Get Angle To Target function a lot, but in the end I don't think I really care what angle my player is to the enemy, he will always have to face the enemy in order to push him.

What I really need to know is...


How do I obtain my players forward direction and then apply a translate to the enemy that forces them into that direction, regardless if they're facing forward, backwards, sideways, or even upside down?  I -cannot- figure it out.

Thanks for ANY tips.
(Sorry for the crappy image, I was hoping maybe if someone else was a visual person like me they might get an idea how to fix my problem, hehe)

4ppleseed

  • Full Member
  • ***
  • Posts: 226
Re: Pushing enemy in correct direction
« Reply #6 on: October 13, 2014, 07:44:36 AM »
How about you store the player's X position as a global variable and have the enemy store it’s own X position as a local variable.

When the collision happens, Float Compare the two. If the player’s X is less than enemies X knock enemy one way and if its greater knock the enemy the other direction.

Edit: I'd imagine the reason why your enemy always goes the same way is because when it turns around you flip the Scale X or something.

How about every time you flip the enemy you also set a local Bool that says Facing Right? = True or False. When the player hits, Bool test If facing right = knock one way, If facing left = knock the other way.
« Last Edit: October 13, 2014, 07:48:59 AM by 4ppleseed »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Pushing enemy in correct direction
« Reply #7 on: October 13, 2014, 07:49:59 AM »
You only need the direction the player is facing.

Use Transform Direction, store the vector and apply force/translation with it on the target enemy.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

beaumint

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Pushing enemy in correct direction
« Reply #8 on: October 13, 2014, 09:39:20 AM »
Thank you so much for the responses.  Unfortunately, I cannot get transform direction to work... for anything.  I've tried so many different scenarios.



I store the vector from my player into vectorCollision Vector3 variable and no matter how I try to use the variable... nothing works.  When I use the images setup above the enemy registers the collision with the player but don't move.  They just sit still.  No rotation, no nothing.  I've even tried multiplying the Vector3 by 100, just to see if the number was too small to see a difference in the translation.

I understand how transform direction works.. to a degree, but I don't understand how to apply the Vector3 to force movement in my enemy.

Sorry if I'm missing something very simple!  I wish I could figure it out on my own but I'm at my wits end!

Haha, thanks again for the attempts to fix my problem,
Cheers!
Drew

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Pushing enemy in correct direction
« Reply #9 on: October 13, 2014, 09:53:30 AM »
Hmm okay so can the player hit more than one enemy?

Maybe you're looking for the collision Normal. You can use Get Collision Info to store the collision information when the player hits them, that will give you the normal of the collision instead of the facing normal of the player.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

beaumint

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Pushing enemy in correct direction
« Reply #10 on: October 13, 2014, 08:48:50 PM »
Thanks again for your time.

I'm trying to look up information on Collision Normals but coming up pretty short.

In another thread I saw you mention that finding collision information is impossible to do when you use 1) kinematic or 2) box collider trigger.

Would this be why its literally impossible for me to be able to do detect any kind of collision from my attack?  I had no idea this would be this difficult to get figured out. lol

Thanks again for your time
-Drew

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Pushing enemy in correct direction
« Reply #11 on: October 13, 2014, 09:43:27 PM »
Its just kind of confusing when you don't know all the different terminologies yet. Once you get it setup you'll start connecting the dots.

So if you're using collisions then you need a rigidbody and a collider. If you're using triggers then the colliders simply need to be set to Trigger. Additionally you can only use the Trigger actions for Triggers, and the Collision actions for the Collision actions like Get Collision Info. Hitting a Trigger is not the same as a Collider and the actions have to be used correctly for them to work. Unless your units have Triggers rather than Colliders, then that isn't your problem here.

A Vector3 is just 3 float values, it's most often used to express a position in world space (like 47, 0, 38). A Normal is just a Vector3 that is normalized. It expresses a direction, all of the values will be less than 1, like (0.2, 0.29, 0.4).

So when you use Get Collision Info and choose the Contact Normal you're storing a direction that you could use to make a collider face the other. So you just take the Contact Normal and use Translate (or Add Force, whatever you're using) with that Normal and it should move in the correct direction relative to the collision.

Hope that clarifies.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

beaumint

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Pushing enemy in correct direction
« Reply #12 on: October 16, 2014, 06:26:47 PM »
FINALLY! I got it!

Thank you so so so so much Lane for your patience.
It took me a few days (I took a break and came back to the problem) but now that I've read up so much I fully understand collision, especially the difference between triggers and collisions.

I feel like I have a much better grasp on the whole system.
I cannot thank you enough, cheers!!

-Beaumint

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: [SOLVED] Pushing enemy in correct direction
« Reply #13 on: October 16, 2014, 07:38:05 PM »
Awesome!

No problem, feel free to ask questions.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D