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 dfghdh · Mar 18, 2013 at 11:12 PM · javascriptfpsworldspacelocalposition

Weapon ("Snapping") Socketing FPS

Hi,

I am making a system where by a player in a FPS has a socket parented to their capsule collider which indicates where any weapons this player picks up need to be located.

It then needs to, upon acquisition, snap the weapons mesh onto that socket. However the catch is there is an offset from the meshes transform which is in the form of a socket on each weapon. It is the two sockets (player and weapon) that need to be aligned but the meshes transform that needs to be moved.

This means I need to calculate the meshes new Vector3 position (the rotation and scale are taken care of) based on the location it has to go (the players socket) the location its snapping onto (the weapons socket) and the location of what is actually displayed (the weapon mesh).

I am pretty sure this comes down to differences between local and world space. Does a childed game objects position represent an offset from the parents position?

If so could I just align the meshes transform and the player socket and then create a new Vector3 equal to the meshes position - the sockets position. When my weapon is being attached it will be existing in world space and so the meshes transform will not be childed to anything else.

TLDR: Is a games objects childs transforms position a representation of an offset from the parents position?

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 Fattie · Mar 19, 2013 at 07:56 AM 0
Share

just set the transform.localPosittion

1 Reply

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

Answer by Julien-Lynge · Mar 18, 2013 at 11:45 PM

TLDR answer:

Childing a game object to another means that it's transform is relative to the local coordinate space of the parent. In other words, the parent exists at (0,0,0), zero rotation, and (1,1,1) scale, and the child is based in that coordinate system. So yes, a child's transform position is an offset from the parents position, according to the parent's rotation and scale.

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 dfghdh · Mar 18, 2013 at 11:52 PM 0
Share

so say the player socket was at O = (0,0,0) and the mesh was at some arbitrary point say P = (10,3,6) the weapon socket is childed to the mesh and has a position of $$anonymous$$ = (1,1,1) which in world space is (11,4,7) (?). That means since I want the two sockets to align I need to set the position of P to be O - $$anonymous$$ = (-1,-1,-1)? Then $$anonymous$$ which is local to P would be (0,0,0) same as O.

avatar image Loius · Mar 19, 2013 at 08:13 AM 1
Share

This is true for transform.localPosition, localScale, and localRotation only. The world variations are .position, .lossyScale (which cannot be set), and .rotation

You can set weapon.position = socket.position, which is the same as (weapon.parent = socket.parent; weapon.localPosition = socket.localPosition)

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

12 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

Related Questions

Distance on fps 3 Answers

Lens-Flare Muzzleflash 0 Answers

Enemy death help 1 Answer

Class member Vector3 based on local transform 1 Answer

Health Script 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