#Problem with Grab mechanic

19 messages · Page 1 of 1 (latest)

tender merlin
#

In my project, i wanted to create a similar grab mechanic with the left for dead charger where he grabs you and continuously smashes you to the ground, and the only way to break free is to kill the charger.

using this code i am somewhat able to achieve my goals:
match state:
"idle":
pass
"grabbed":
if crawler == true
global_transform.origin = use_position.global_transform.origin
however i get an error called Invalid get index 'global_transform' (on base: 'previously freed instance'). And whenever i dont move(WASD) while being "grabbed" the game crashes, while if i move(WASD) while being "grabbed" the game doesnt cras.
this is odd for me as i dont know how i can fix this, nor know what the issue is, i have tried "is_instance_valid()" and it only creates issue when the enemy(crawler) is killed, does any of you know what might be the reason/issue for this? and if so, what could i do to fix this? "note, if you guys have a better approach with the grab mechanic, i would be happy to use that instead, thank you in advance!"
Theres some clips so you can see the issue in more details. "Left clip (Not moving/using WASD) Right clip (Moving/using WASD). SOLVED

empty orbit
#

Have you tried using a remote transform node instead. It should work out of the box, and you prob dont need to do anything when the enemy us deleted.

tender merlin
tender merlin
empty orbit
#

the remote transform node is used to copy transforms from 1 node to the other. I would start by adding the remote transform node as a child to your monster. When you want the grab to start just fill the remote_path variable of it with the node path to your player. Remember to disable rotation and scale from the remote transform node to avoid unwanted behavior
https://docs.godotengine.org/en/stable/classes/class_remotetransform3d.html

tender merlin
#

Forgive me for sayings, knowing you helped me so much this far ahead, but i dont quite understand the last part of what you said, specifically "when you want the grab to start just fill the remote_path variable of it with the node path to your player" i read the documentation you said but that also made me even more confused, im still a beginner so i cant really read it nor understand all of it. and there is not much youtube videos regarding remotetransform2D, so can i ask that you spoon feed me exactly what to add to my code " match state:
"idle":
pass
"grabbed":
if crawler == true:
global_transform.origin = RemoteTransform2D.global_transform.origin" just incase you didnt know, that code is from my player.gd and not enemy.gd, also both player and enemy are different scenes, and are a instanced from another scene called world... thank you once again, and forgive me for being too inexperience and dumb dumb

empty orbit
#

it will be a bit hard for me cause i work with c#. You prob wont be doing the work in the player script. It will happen on the enemy script most likely.
When you want an enemy to grap the player, 1st step is to get a referance to the player. 2nd to find the remote transform in the enemies hierarchy. and final to fill the remote_path variable of it with the player node path.

#

this will be placed on your enemy script most likely. sophia should be then replaced with your player

tender merlin
#

Oh i see!

#

but i did that before, and in that code "sophia.get_path()" there was an error

#

I forgot what it was specifically, but it had something to do with remote_path having an error

empty orbit
#

try replicating it, it will be useful info.

tender merlin
#

Thanks, ill try it again! thank you so much btw

empty orbit
#

its all good. Hopefully you will be able to help someone else with the same problem in future.

tender merlin
#

When im experienced enough, i definitely will, alot of people has helped me this far, so i will return the favor

#

Ah, i seem to understand alot now, so it seems its much better to add the remotetransform in the enemy script rather than the player script so it doesnt collide nor recieve an error, Thank you so much! ive finally gotten it (i havent coded it yet) but this logic makes so much more sense than what i was trying to do, i will create it now!

empty orbit
#

perfection, good luck with the implementation

tender merlin
#

THANK YOU SO MUCH! i finally figured it out after 2 days!