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 Hydraxia · Sep 02, 2013 at 02:25 PM · terrainobjectcollidefall

Object falling through terrain with script

Hi! First i want to sorry for my english, it's not my native language.

I have this little script that resizes object ( the player ) from 1.0 to 0.5 on the axis Y.

 using UnityEngine;
 using System.Collections;
 
 public class Dodge : MonoBehaviour {
 
     public bool isDodged = false;
     // Use this for initialization
     void Start () {
           isDodged = false;
     }
     
     // Update is called once per frame
     void Update () {
          if    ( Input.GetKeyDown(KeyCode.LeftControl)) isDodged = true;
             if ( isDodged == true ) {
             
                Vector3 scale = transform.localScale;
                scale.y = 0.5f; // This is where it decreases to 0.5
                transform.localScale = scale;
         }
         
          if    ( Input.GetKeyUp (KeyCode.LeftControl)) isDodged = false;
             if ( isDodged == false ) {
             
                Vector3 originalsize = transform.localScale;
                originalsize.y = 1f;
                transform.localScale = originalsize;
         }
     }
 }


I start with original 1.0 value, when i hold down LeftCTRL the player decreases to 0.5, and after i release the button, it goes back to 1.0 Yes, this works, but when it goes back to size 1.0, it falls through the map. I think its because it doesn't has time to calculate colission with map, OR it begins to resize from the center, so a little part remains under the terrain. How could i fix that?

Thank you!

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 YoungDeveloper · Sep 02, 2013 at 02:34 PM 1
Share

Hi, if you are struggling with crouch, check out this post. http://answers.unity3d.com/questions/164638/how-to-make-the-fps-character-controller-run-and-c.html

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by mirkobon · Sep 02, 2013 at 03:10 PM

Add this to your script when it resizes:

transform.position.y += 1;

maybe I'm wrong.

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 Hydraxia · Sep 02, 2013 at 03:18 PM 0
Share

It's not a bad idea, but it doesn't looks good when playing in 3rd person :/

avatar image mirkobon · Sep 02, 2013 at 03:22 PM 0
Share

Didn't know it was 3rd person try make an animation than?

avatar image
0

Answer by save · Sep 02, 2013 at 03:29 PM

You could Raycast downwards to get the position where to place the character right after rise. You would want to shoot it a bit above the player towards -Vector3.up. Then place the character with an offset of 50% of body height (.5f in your case?), if pivot is at center. Think in terms of where the collider is ending up from crouching, rising and standing, it's usually good to monitor it with the Scene view while playing.

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

18 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

Related Questions

My character will fall through the floor with this script:... 1 Answer

How can I make a sound deploy after colliding with a certain object (or terrain)? 1 Answer

When my prefabs are instantiated they don't have their script attached 1 Answer

Can't use tree brush tool 0 Answers

Keep an object on the gound. 2 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