Hey guys (sorry if repeating - having troubles forums…) im making 2d sidescroller puzzle game (using only keyboard) with push-pull/drag objects (drag/pull box to some place to be able to jump on some higher surface)… i set up push object script using AddForce, but i cant find any tutorial or script itself for dragging object on collision (character standing near box to drag/pull it holding down button i.e. “E”)… maybe something similar like now so popular LIMBO game… can anyone help me with this?
1 Answer
1Just out of my head, did you try negative AddForce? (never worked with AddForce so not sure if this works)
If that doesn’t work, You can try setting some bool if the object is being dragged and if so, make it’s position close to your character position.
yes i tried negative force and i couldn't make it work :C tho idea about position near char seems possible tho don't really know how to do that :3
– KaashaHere is my thought about this: Add a trigger area to your dragable object (add a collider and check the trigger box). Then, have a check for when entering the trigger area, follow the player (direction doesn't matter).
– dorpeleg
There are multiple ways of pulling. You can create a joint between two object (can work well with Rigidbodies), you can "magnetize" one object so that either based on a state or distance it will use force to drive itself towards an other object, you can write a script that pulls an object towards another using Transform.Translate(), and you can make an object a child of another object. If you decide on an approach given your game mechanics, I can probably point you to more information or a sample script.
– robertbucan that magnetism be made with "hit" or "on key" mode? as i'm desperate trying out things with this option.. and just to make sure.. those child of object's u mean like "Stick" under player object and if that stick is colliding with "box" then its starts pulling? if so i would be very happy if u could provide some sample script for that :3
– Kaasha