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 soand · Apr 07, 2014 at 07:41 PM · gameobjectprefabmovingmove an objectplacing

Holding your gameobjects

hello guys,

i'm trying to make a game where you are able to spawn creatures, when you press a button a prefab will be shown in front of the player, and it should move and rotate with the players point of view.

i'm new to unity and coding in general can someone give me a pointers to how to go about this? i can successfully instatiate the gameobject but i have no idea how to make the gameobject move as my player is moving. And stop moving when the player presses "Fire1"

thanks in advance, any help is greatly appreciated!

Comment
Add comment · Show 1
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 khos85 · Apr 07, 2014 at 07:51 PM 0
Share

Hi, How about if a key is pressed then you run code:

var target : GameObject; function Update () { if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.)){ transform.position = target.transform.position; transform.rotation = target.transform.rotation;

}}

Drag the gameobject into the target slot at the editor view when script is added to playerobject. This would match the position of the target.

Untested but hope it helps :)

2 Replies

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

Answer by MrSteve1 · Apr 07, 2014 at 07:47 PM

This one should be fairly straight forward,

Store the camera in a Transform variable. In the Start() function, get the camera game object with gameObect.FindWithTag("MainCamera").transform;

an then attach the creature object to the camera using transfom.parent = camObject and then match its transform, then just at roughly 10 units to he Z Axis.

Then as soon as Fire1 is click, set parent to null.

Comment
Add comment · Show 5 · 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 soand · Apr 09, 2014 at 08:38 AM 0
Share

Thank you for the answer!

i just had the time to check it now but as soon as i store the camera in a transform variable (i am using C#) i get the error "cannot implicitly convert type UnityEngine.Transform to UnityEngine.GameObject" is it just me that is writing the code wrong or is this a common problem?

avatar image soand · Apr 09, 2014 at 08:40 AM 0
Share

oh! i just wrote the code wrong i figured out what to do thank you very much for the help!

avatar image soand · Apr 09, 2014 at 10:08 AM 0
Share

A quick question again.

can i only run the if (input.GetButtonDown("fire1")) statement in the void Update? because it doesnt register when i use the Fire1.

avatar image exvalid soand · Nov 13, 2017 at 04:36 PM 0
Share

yes correct only in update as it need to know every frrame if being used

avatar image flamy · Apr 09, 2014 at 10:09 AM 0
Share

post questions/doubts as comments not an answer

avatar image
0

Answer by exvalid · Nov 12, 2017 at 10:27 PM

Hey I have added 2 Script to Complete a full Grab toggle and ready to move code,

Fixed An Inversion Error and a Euler read error while moving. since yesterday it is now working as stated below

ObjectGrabIdAndLock, ObjectReplyIdAndMove

ObjectGrabIdAndLock goes on Main player,.. ObjectReplyIdAndMove goes on Moveable Objects remember to add layers in you want to hit in inspector and pick the Headcam Ect

Updated Scripts Since the other week now with full movement And Rotation and Full Inversion Options

This is Complete bar Diagnals and Mouse Rotation as im adding this now, you want to use the option OverideDiagnals and possibly UseDefaultRotation if u hate my defualt.

too add mouse copy the whole auto inversion and paste it underneath and swap the names to the mouse names instead of the default keys its a mission dont attempt it lol. i will do this over the week as still cleaing up the script its pretty large, Please contact at Exvalid@gmail.com To give me job coding.

cheers Ryan kappeslink text Exvalid@gmail.comlink text


objectgrabscripts.zip (11.7 kB)
Comment
Add comment · 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

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

25 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Objects flickering between dark and light 7 Answers

Get the name of an instance's prefab at runtime? 0 Answers

Create with code 2.2 pizza not shooting 1 Answer

difference between prefab and gameobject in listening event 1 Answer

Troubles instatiating a gameobject with rotation 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