• 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 Yucel · Oct 17, 2014 at 06:37 PM · first person controllergrabflag

first person controller carry flag

I ve a terrain, in terrain i ve a first person controller and also a flag on a hill. When FPC triggers the flag, FPC grabs the flag and carries it. The problem is, when FPC makes a rotation, flag is staying behind the FPC. here is my script;

 #pragma strict
 
 public var grab = false;
 public var firstPC : GameObject;
 var flagPos : Vector3;
 var flag: Transform;
 
 function Update () {
     if(grab== true)
     {
         flagPos= Vector3(firstPC.transform.position.x, firstPC.transform.position.y, firstPC.transform.position.z);
         flag.transform.position = Vector3(flagPos.x,flagPos.y,flagPos.z);
     }
 }
 
 function OnTriggerEnter (other : Collider) {
     grab= true;
 }
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 robertbu · Oct 17, 2014 at 06:40 PM

In addition to putting the flag at the position, you also want to parent the flag. Insert below line 12:

   flat.transform.parent = transform;

I'm assuming here that this script is on the object that is going to be carrying the flag. If not, you need to use that transform. In addition, I don't see a definition for 'bayrakPos' in the above script.

Comment
Add comment · Show 2 · 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 Yucel · Oct 17, 2014 at 06:56 PM 0
Share

bayrakPos is flagPos sorry for that my mistake.

yes it works with a little correction.

 flag.transform.parent = firstPC.transform;

thanks.

how can i give offset in x ?

avatar image robertbu · Oct 17, 2014 at 06:58 PM 0
Share

Not sure what specifically you mean by 'offset in the x', but the position you put the flag in this line:

    flag.transform.position = Vector3(flagPos.x,flagPos.y,flagPos.z);


....will be the relative pos to the parent, so maybe you mean something like:

   flag.transform.position = Vector3(flagPos.x + 0.5,flagPos.y,flagPos.z);

Actually it should be something like:

   flag.position = firstPC.transform + Vector3(0.5,0,0);

This will place the flag relative to the 'firstPC.transform'. You want to do this before parenting. Or alternately after parenting you can do:

   flag.localPosition = Vector3(0.5,0,0);

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

objects falling when I use my grab script 1 Answer

How to have controlles switch from FPC to a RC Car 1 Answer

Help with sticky FP controller script 1 Answer

Main character grab on to a spinning object 1 Answer

Get the FP Controller to stay in last position after stopping the game? 0 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