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 decamonos1 · Jul 15, 2012 at 11:18 PM · physicsplayercolorfunctionschanging

Changing the color of a block when a player walks on it?

I want to make a script that changes the color of a block when the player touches it. I am trying

public Transform myTransform;

void Start () { myTransform = transform; }

void OnCollisionEnter (){ myTransform.renderer.material.color = Color.green; }

This code however is only working when a simple object with a rigid body touches it. And adding a rigidbody, or changing the collider for the player doesn't work. What will fix my script, and why doesn't this one work?

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 Avaista · Jul 16, 2012 at 01:00 AM 0
Share

Does your character have a collider on it or a character controller on it?

avatar image decamonos1 · Jul 16, 2012 at 02:56 AM 0
Share

It has a character controller on it.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by iHaveReturnd · Jul 16, 2012 at 01:01 AM

I just tested this out in unity and found that the character is sitting on top of the ground. If I manually moved the player controller down into the ground in unity the ground would change green. So I believe the controller is having itself sit above it, causing the collision to not really happen.

I'm fairly new to unity so that may not be the case, but that's what I found from trying.

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 Avaista · Jul 16, 2012 at 01:21 AM 0
Share

That, my friend, is the skin width.

avatar image decamonos1 · Jul 16, 2012 at 02:57 AM 0
Share

I tried the same thing, and the floor still didn't change.

avatar image
0

Answer by Avaista · Jul 16, 2012 at 04:05 AM

Okey Dokey, Collisions seem to be the word of the day today.

Firstly, Please go to http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html and scroll down to the bottom.

Welcome to the Collision Action Matrix. Learn it. Love it. Love It. LOVE IT.

Now you are working with a character controller, which is a bit different. It inherits from collider, has a capsule collider, but does not quite act like one.

Try making the cube on the floor a Kinematic rigid body.

If this does not work(I don't think it will), add a capsule collider to the character controller. Make sure that the radius of this collider is greater than the character controller's radius + the skin width. Now give it a shot. The cube you are walking on should be a rigidbody, if it is not then I guess you didn't love it enough. ;)

The following is more informational, the above should have fixed the issue, let me know if it didn't.

The skin width is an odd thing that the documentation does a sub par job(IMO) of explaining(at least when considering how often the component is used)

It allows objects to penetrate the Character Controller.

Now looking at the capsule, you would think: "oh: so it can go up to {skinWidth} into the capsule."

Not so much. In reality, imagine it as a force field around the capsule with a thickness of {skinWidth}. If some thing enters that force field, it will not let the controller move in that direction, but also doesn't force it out. This results in less jitter.

To see this, put the skin width really high and pull the capsule up and play(assuming the capsule has some gravity (either SimpleMove or gravity added Move) Watch as you float in the air like a levitating Multivitamin.

Also, another solution would have been to use OnControllerColliderHit(), which you can check out here.

Comment
Add comment · Show 8 · 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 decamonos1 · Jul 16, 2012 at 05:58 AM 0
Share

I am very sorry to inform you that none of the above solutions worked, even in the slightest. Thank you for the very informative answer though!

avatar image Avaista · Jul 16, 2012 at 06:28 AM 0
Share

That is very interesting.

So... The cube on the floor has a collider, that is not a trigger, that has a rigidbody, without using gravity.

The player has a character controller, with a collider that extends farther out than his controller capsule plus his skinWidth?

This does not work with kinematic on the rigid body set to either on or off?

If this is not working for you, just make a [damn] trigger and add it above the cube.

avatar image decamonos1 · Jul 21, 2012 at 04:37 AM 0
Share

I did this too. Nothing is working and I don't know why.

avatar image Avaista · Jul 21, 2012 at 07:01 AM 0
Share

Okay.......I have a random question...Go To Edit->ProjectSettings->Time

Is the timescale 0? if so turn it to 1.

If this does not work, we can set it up for you to send me the project(if your are allowed to do so) and I can take a more indepth look at the scene, if you want.

avatar image decamonos1 · Jul 22, 2012 at 08:34 AM 0
Share

It was already 1. So lets set up me sending you the project, as I am at wits end with it.

Show more comments

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

SphereCast to detect remote player 1 Answer

Enemy Projectile not flying in the right direction (needs to fly toward player),How to make enemy projectile fly toward player? 2 Answers

Collisions causing Rigidbody to go Haywire and move randomly. 1 Answer

Issues Making Character Move With Rigidbody 1 Answer

Changing tint color of skybox via script 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