- Home /
Drag object using only keyboard in 2d sidescroller
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?
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.
can 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
Answer by dorpeleg · Mar 18, 2013 at 08:46 PM
Just 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
Here 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).
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Moving a rigidbody onto exact mouse position using rigidbody.MovePosition? 1 Answer
Another camera drag script, can anyone figure out these errors? 1 Answer
Passing stuff from script to script (setting change-able waypoints) .... 1 Answer
OnDrag Draw Line For Pathfinding... 1 Answer