Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by BigBlob · Apr 09, 2012 at 02:15 AM · rigidbodyobjectpuzzlepull

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BigBlob · Apr 09, 2012 at 04:41 PM 0
Share

I see the script look good so basicly the first one I attach to an empty gameObject? and the second one on the player?

avatar image
0

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:

  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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BigBlob · Apr 09, 2012 at 04:42 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges