- Home /
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
Answer by Posly · Apr 09, 2012 at 02:44 AM
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 see the script look good so basicly the first one I attach to an empty gameObject? and the second one on the player?
Answer by kolban · Apr 09, 2012 at 02:57 AM
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:
Selecting the box to be pulled with a key press or mouse click
Moving the "player" character
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.
or maybe just attaching a FPS Input script on the box and set to false the n make a script that when in raycasting at 10 I press jump and i activate the FPS Input on the box
Your answer
Follow this Question
Related Questions
How to grab objects in 3rd person LITTLE BIG PLANET STYLE 2 Answers
Parent Object 0 Answers
My rigidbody gets destroyed 2 Answers
How push the object? 2 Answers
Amnesia like objects, in unity. 2 Answers