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 Matt P 3D uk · Aug 09, 2013 at 11:32 AM · parenting

Parenting single transform attribute with offset?

I want the parent/link the transforms of two objects in one axis only with an ability to add an offset.

Similar to how you can set a Point Constraint to a single axis in Maya.

I have tried parenting through scripts had no progress.

It for a mini map camera that will operate two floors for a building. When the player moves up and down the floors, I what the camera to follow the player in the Y but not in the X and Z. This will allow me to position maps I have made in Photoshop in relevant position. so as the player moves up and down the different floor maps are reveled.

Thanks

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by whydoidoit · Aug 09, 2013 at 11:40 AM

You will need to write a script to have one object follow the other, rather than using parenting to achieve the effect you want.

FollowTargetObject.cs

 using System;
 using UnityEngine;
 
 public class FollowTargetObject : MonoBehaviour
 {
       public Transform thingToFollow;
       public Vector3 offset;
       public Vector3 mask = Vector3.up;
 
       void LateUpdate()
       {
            if(thingToFollow)
            {
               var followPosition = thingToFollow.position + offset;
               var currentPosition = transform.position;
               transform.position = new Vector3(Mathf.Lerp(currentPosition.x, followPosition.x, mask.x), 
                   Mathf.Lerp(currentPosition.y, followPosition.y, mask.y),
                   Mathf.Lerp(currentPosition.z, followPosition.z, mask.z));
            }
       }
 
 }

Using this code you can control how much the object with this script attached follows the target object by varying the parameters of mask between 0 and 1.

Comment
Add comment · Show 8 · 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 Matt P 3D uk · Aug 09, 2013 at 01:05 PM 0
Share

Thanks for your help.

I have a attached this C# script to camera that i want to follow the object.

I'm getting the following error in the console: Assets/Scripts/mapcam.cs(26,14): error CS0116: A namespace can only contain types and namespace declarations

I'm guessing i need to tell it what object i want it to follow but i'm unsure where to specific this.

I have only been using Unity for couple of weeks and co$$anonymous$$g from a 3D animation background i'm struggling with the scripting.

Thanks again for your help.

avatar image whydoidoit · Aug 09, 2013 at 01:36 PM 0
Share

Hi $$anonymous$$att - well it sounds like you have some code weirdness going on! That message implies an incorrectly formed .cs file.

avatar image whydoidoit · Aug 09, 2013 at 01:37 PM 0
Share

Perhaps you could post the code to mapcam.cs?

avatar image Matt P 3D uk · Aug 09, 2013 at 02:09 PM 0
Share
 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$ini$$anonymous$$apCam : $$anonymous$$onoBehaviour {
     
       public Transform thingToFollow;
       public Vector3 offset;
       public Vector3 mask = Vector3.up;
     
     // Use this for initialization
     void Start () 
     {
     if(thingToFollow)
             {
               var followPosition = thingToFollow.position + offset;
               var currentPosition = transform.position;
               transform.position = new Vector3($$anonymous$$athf.Lerp(currentPosition.x, followPosition.x, mask.x), 
                   $$anonymous$$athf.Lerp(currentPosition.y, followPosition.y, mask.y),
                   $$anonymous$$athf.Lerp(currentPosition.z, followPosition.z, mask.z));
            }
       }
  
 }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
avatar image whydoidoit · Aug 09, 2013 at 02:50 PM 0
Share

Well the Start function should be LateUpdate and the class name must be exactly the same as the filename including capitalization.

Show more comments

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

15 People are following this question.

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

Related Questions

iTween moving all children the same way the parent object does 0 Answers

Manipulating Instanced Object 2 Answers

i want the camera stop follwing my player only on y axis when he jumps... 4 Answers

how to make an objects rotation independent from its parents. 2 Answers

Prefab changing dimensions when parent changed 1 Answer


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