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 /
This question was closed Jan 30, 2015 at 11:38 PM by Major for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Major · Jan 30, 2015 at 03:40 AM · gameobjecttransformobjectgunpickup

Setting Without Altering Object Scale and Collider Scale

I am making a weapon/object pickup script and when I pickup the object and throw it the collider scale gets wacked out. It gets worse every time you pick up the object and throw it as well. I also tried scaling the object to be smaller but when I picked it up it reverted the scale. I am not sure what is causing this. Any help would be appreciated, thanks!

 using UnityEngine;
 using System.Collections;
 
 public class GunControl : MonoBehaviour {
 
     public bool auto = false;
     public bool enabled = false;
     public bool showGUI;
     public float fireRate;
     //float curTime;
     public Transform _camera;
 
     public float yPos;
     public float xPos;
     public float zPos;
 
 
     float xRot;
     float yRot;
     float zRot;
 
     float xrotv;
     float yrotv;
     float zrotv;
 
     void Update () {
         if(enabled == true){
             xRot = Mathf.SmoothDamp(xRot, _camera.GetComponent<CameraControl>().currentXRot, ref xrotv, 0.1f);
             yRot = Mathf.SmoothDamp(yRot, _camera.GetComponent<CameraControl>().currentYRot, ref yrotv, 0.1f);
             //transform.forward = _camera.forward;
             transform.rotation = Quaternion.Euler(xRot, yRot, 0);
             //currentXRot = Mathf.SmoothDamp(currentXRot, verticalRot, ref xRotV, smoothDamp);
         
             if(Input.GetButtonDown("Fire2")){
                 enabled = false;
                 transform.SetParent(null);
                 transform.rigidbody.isKinematic = false;
                 transform.collider.enabled = true;
 
                 rigidbody.AddForce(transform.forward * 1000f);
             }
 
         }else{
             if(Vector3.Distance(transform.position, _camera.position) <= 3f){
                 showGUI = true;
             }else{
                 if(Vector3.Distance(transform.position, _camera.position) > 3f){
                     showGUI = false;
                 }
             }
         }
 
         if(showGUI && Input.GetKeyDown(KeyCode.E)){
             enabled = true;
             showGUI = false;
             transform.SetParent(_camera);
             transform.localPosition = new Vector3(_camera.localPosition.x + xPos, _camera.localPosition.y + yPos, _camera.localPosition.z + zPos);
             transform.rigidbody.isKinematic = true;
             transform.collider.enabled = false;
         }
     }
 
     void OnGUI(){
         if(showGUI){
             GUI.Box (new Rect(Screen.width / 2, Screen.height / 2, 300, 50), "Pick up " + transform.name);
         }
     }
 }
Comment
Add comment · Show 2
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 Simon-Larsen · Jan 30, 2015 at 04:04 PM 0
Share

I guess this would happen if the scale of _camera wasn't 1:1:1. $$anonymous$$aybe setting the worldPositionStays flag to true would solve the issue.

avatar image Major · Jan 30, 2015 at 11:37 PM 0
Share

Well I feel incredibly dumb right now, the scale of the camera got wacked out for some reason. And of course it fixed the problem! Thanks!

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Move hit.point 1 Answer

Can't Return the Tag of a Child Object 4 Answers

Merging Object 1 Answer

help hiding object? 2 Answers

How to differentiate between prefabs on collision. 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