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 spenmich · Feb 24, 2017 at 12:15 AM · c#fpsscritping

First Person and Lifting

Hey all,

I'm starting a project where you play in first person. My first question is how to implement that- I tried using the First Person that came with Unity, but I'm unable to look right at left. Secondly, I want to be able to lift other objects so that they hover in front of me and I can walk around with them- Portal style. I'm new to unity and C# and I would really appreciate the help!

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
1
Best Answer

Answer by UnityCoach · Feb 24, 2017 at 12:34 AM

Unity suggest a Component based architecture. So, if you're going to use the default First Person Controller, I would suggest to develop a GrabObject component that you put on the same game object and that communicate with it.

You also need a Pickable component that you add to game objects that can be picked up. The pickable object could also simply use an object tag "pickable" and you can put all mechanic in the GrabObject component.

The component will need to :

  1. Find objects in the field of view, or center of the screen. You can use Physics.Raycast and the object tags for this.

  2. Use some Input to trigger the pick-up

  3. Then you can reposition the object and parent it to your 1st Person Controller using its Transform

  4. You can then use some other Input to drop the object, and then use RayCast again to put it back in the world where you stand. The object will need a Collider and RigidBody if you want it to fall down.

This should be enough to get you started. Good luck!

Comment
Add comment · Show 6 · 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 spenmich · Feb 24, 2017 at 01:15 AM 0
Share

Just a quick question- when I add the Rigidbody First Person Controller I'm able to move, but I can only look up and down- not left and right. I've checked the Input, and everything should be in order. Any ideas? Thanks so much!

avatar image UnityCoach spenmich · Feb 24, 2017 at 09:35 AM 0
Share

I haven't worked with it for a while. Looking at the FirstPersonCharacterGuidelines doc, I see :

The first-person character is made up of a few components acting together. The FirstPersonCharacter script provides the functionality of moving, strafing and jumping. The Simple$$anonymous$$ouseRotator provides the functionality of turning the body of the character left and right, and another copy of the same script on the "FirstPersonCamera" controls the looking-up-and-down effect.

Though, when I look at the Prefab it looks fairly different form this. It happens that they change the API and don't update the assets. Although, it works fine on my version, using 5.5.0p1 on $$anonymous$$ac.

avatar image spenmich UnityCoach · Feb 24, 2017 at 05:48 PM 0
Share

I had to use the prefab that came with the assets, but I was able to modify it to work how I wanted it to. Thanks so much!

Show more comments
avatar image spenmich · Feb 25, 2017 at 01:27 AM 0
Share

Hey UnityCoach!

Sorry to bother you again- one last question.

I'm trying to get the Vector3 transform of that hit object. Right now my code to get that is: hit.collider.transform.gameObject But it gives me the error `UnityEngine.GameObject.transform' cannot be assigned to (it is read-only) '

How would I do this? Thanks so much again!

avatar image UnityCoach spenmich · Feb 25, 2017 at 12:23 PM 0
Share

No problem. So, let me give you a bit of theory :

The transform property links to the Transform component itself, and only offers a get;

The Transform component is a bit special in Unity, it's the only component that cannot exist without a GameObject, as much as a GameObject cannot exist without a Transform.

Anyway, you can't assign pre-built components to GameObjects, as the AddComponent method only takes a type to add a new component, so you usually add the component and modify it right after, as opposed to building it and setting it up before you add it.

Now, with the hit, I understand you're using a RaycastHit. $$anonymous$$now that it has a point property, which returns the point of impact as a Vector3. If you want the position of the hit object, you want to use RaycastHit.transform`.position` which you can read and write. Though, remember that Vector3 is a struct, not a class. So you can't modify one of its components, you have to build a new one and replace it.

 hit.transform.position.y += 1f; // won't work, you need to use the following :
 Vector3 pos = hit.transform.position;
 pos.y += 1f;
 hit.transform.position = pos;

Hope this helps.

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

321 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 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 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 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 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 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 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 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 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 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 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 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 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

What is the standard direction of a character relative to its own axis? 1 Answer

How can I teleport the player when a bonus level timer runs out? 0 Answers

Build navmesh during runtime 0 Answers

Partial synchronization of camera with the bone of the head or other object 0 Answers

Virtual hands in FPS MMO game 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