Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by undead504 · Jun 18, 2016 at 05:47 AM · transformprefabpositioncopyy axis

How to instantiate a prefab infront of First Person Controller

alt textHello there im trying to Instantiate my Game object right in front of the Player and all is good but the Object is just a little off the terrain.

Here is what I got So far

 var DupObject : GameObject;
 
 if (Input.GetKeyDown(KeyCode.F)){
 Instantiate(DupObject, transform.position + transform.forward*distance, transform.rotation);
 }


bandicam-2016-06-17-21-49-40-564.jpg (290.2 kB)
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 Cherno · Jun 18, 2016 at 12:22 PM 1
Share

Cast a ray downward, starting at the xy position of the placement spot but high up in the air. Use the hit.point (the point where the ray hits the ground) for the "real" placement spot.

1 Reply

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

Answer by undead504 · Jun 18, 2016 at 01:21 PM

First off let say Thanks @Cherno you Made me Look harder at my code and really think. OK so the DupObject was has High as the Hit and I added some code on the update to make it always =0 on the y AXIS. here is my Code if any one wants it.`#pragma strict var DupObject : GameObject; var distance : float=5; var Spot : GameObject; var OBJ : Transform; var Layer : int=1; var YAxis :float=0; function Start () {

}

function Update () { Spot.transform.position.y=YAxis; var foundHit :boolean=false;

var hit : RaycastHit; if (Input.GetKeyDown(KeyCode.E)){ Instantiate(DupObject, Spot.transform.position, transform.rotation); }

if (Input.GetButton("Fire1")){ foundHit= Physics.Raycast(transform.position,transform.forward,hit,Mathf.Infinity,1<

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Problem with Seek Missile and finding enemy prefab new position. 0 Answers

Player Floating 0 Answers

Stop moving gameObject and push it back 0 Answers

How to transform position of one object to the exact position of another object? 0 Answers

How to update your position your every frame 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