- Home /
How to Grab an Object or Enemy
I know that to achieve a grab and choke system like in dishonored animation is involved . But thats not what i'm trying to get at. Ideally i want to know how to actually have a grab and choke system where your player grabs an enemy and you hold down a button for a certain amount of time until hes dead or lost his breath.
Here are my thoughts of what that system or code would require without animations:
Perhaps when my player is close enough to the enemy so having a variable to check distance between player and enemy .
Once thats checked at a certain distance where you are able to grab the enemy then the grab feature is available to use.
Here is where i just brainstorm ideas:
when the grab button is pressed eg// button a . The enemy's transform position equals the players transform position. So if i'm not mistaken the enemy becomes a child or parent of the player .
Whilst this is true disable all of the enemy's characteristics and enable a struggling characteristic which is only true when the player is grabbing the enemy.
Then to make sure the choke is successful you have to hold down the button A for example for a certain amount time. So time being used as a variable
After the choke is successful the enemy basically dies and a ragdoll of it instantiates
Or involving animations play the lost breath animation for a certain amount of time which is just the enemy just collapsed on the floor and make that Clamp forever.
To take it a step further you can drag the enemy around to hide him only if the above is true. Meaning the dragging of the enemy around function only activates then.
Ideally i know its something about transform positions and parenting childing but i'm not the greatest when it comes to coding things involving positioning especially when i want to position something the way i want. Also i was thinking it would involve a Get component feature meaning when i pressed the grab button and thats successful send a value or i think true to a function in the enemy class which is waiting to receive a value and once it has receivec that value then you disable the characteristics and enable the struggling one.
Any Guildlines or Help would be appreciated and it doesn't have to involve animation its just the functioning of the grab and choke system I'm concerned about. Thanks !!
One thing to be careful while parenting is that the when the enemy gets parented to the player, its local position might change. $$anonymous$$aybe, have an empty GameObject inside the Player and set its local position to (0,0,0) and then parent the enemy to this empty GameObject rather than the player directly.
You could also try it without parenting it to the player. By manually updating the position of the enemy based on the position of the player and certain joints position.
Hmm yeah i understand what you mean about the empty gameobject maybe thats why i had issues before .
Your answer
![](https://koobas.hobune.stream/wayback/20220613100035im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I access the children of a Transform? 5 Answers
Issues Rotating an object 0 Answers
iTween Parenting oncomplete issue 2 Answers
Parenting tutorial 1 Answer