Pulling Puzzler

I have a push script on my player and now I need a pull script. So then my player could pull the objects my walking up and then pressing a button. Because I’m building a puzzle game like box pusner. Anyone please help, I’m not a good scripter - I’m just 13

What I would do is parent the box to the player, so the box would move with the player. And then make a special moving script for the player just for when he’s pushing or pulling a box. This may be quite hard since you said your not a good programmer, but it will be good experience. Firstly here’s how to parent/unparent an object via code.

var box : Transform;      //a box we'll use an a example
var player : Transform;   //our player
function Update () {
if(Input.GetButton("Jump")) {    //if the player hits the spacebar...
box.parent = player;             //the parent of the box is the player
}
if(Input.GetButton("Fire1")) {   //if we hit the ctrl button...
box.parent = null;               //the box doesn't have a parent anymore, null basically means nothing
}
}

You will have to make a script to check if the box can be pushed/pulled by the player, and if he’s pushing/pulling a box, give him a different movement, maybe something like this:

var speed : float;
function Update() {
transform.Translate(0,0,Input.GetAxis("Vertical") * speed * Time.deltaTime);
}

This will only move your player on the z axis.

Hope I helped!

I suspect that when you are pushing a box you are really applying a physical force to that box and using the physics engine built in to move the objects around. To pull a box, things become trickier. Pulling a box would probably be best achieved by:

  1. Selecting the box to be pulled with a key press or mouse click
  2. Moving the “player” character
  3. As the player character’s position changes, reflect the change in the position of the player to an equal change in position of the box

Unfortunately, pulling is more difficult to achieve in physics modeling in a game engine. Think of two balls on a pool table. When one ball hits another, we can model the energies and trajectory changes from one to another. However, to pull an object is not as “simple” as a momentum transfer from one object to another.