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 bojan1986819 · Mar 13, 2015 at 07:23 AM · movementphysicsballiceslipping

How to create icy floor? c#

Currently I'm working on a top view ball game and I would like to have icy floor parts in it. I plan to do it with using object and collider, but I have absolute no idea how to start. The object (with tag 'IceFloor') would be a few above the ground on y with a trigger on collider and when the player ball would go onto it it should behave like if it would be on ice.

Currently what I have is the ball with a controlling script which is simply moving the ball with arrow keys:

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
     public float speed;
     void FixedUpdate () {
         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
 
         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
 
         GetComponent<Rigidbody>().AddForce (movement * speed * Time.deltaTime);
 
     
     }
 }

I don't have any Physic material yet, not even sure if needed, and if yes where and how. I'm very new to coding. I would really appriciate any help. It would really make me very happy it could work.

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

Answer by SpectreCular · Mar 13, 2015 at 09:14 AM

From http://docs.unity3d.com/Manual/class-PhysicMaterial.html:

"Dynamic Friction - The friction used when already moving. Usually a value from 0 to 1. A value of zero feels like ice, a value of 1 will make it come to rest very quickly unless a lot of force or gravity pushes the object."

Create and apply a Physic material, and play around with the values. Namely, the one shown above.

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 bojan1986819 · Mar 13, 2015 at 09:28 AM 0
Share

Thanks for this hint. I managed to get something which is really close to what I want. I created a Physics $$anonymous$$aterial which has dynamic friction 1 on it and it is attached to the ball. In my player controller script added an OnTriggerEnter for object tag Icefloor and dynamic friction is being lowered to 0. It works just fine, as soon as my ball touches my icefloor object it behaves like on ice. I created an OnTriggerExit for the same tag which should raise the dynamic trigger back to 1. But this part just works strange. $$anonymous$$y ball behaves after leaving the icefloor like if it would be on a glued surface, starts to move very slowly, but only to direct directions(up,down,left,right). But if I try up-right then it is ok. I have no idea what is wrong. Here is my current code:

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController2 : $$anonymous$$onoBehaviour {
     public float speed;
     public float torque;
 
     
     void FixedUpdate () {
         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
 
         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
 
         GetComponent<Rigidbody>().AddForce (movement * speed * Time.deltaTime);
         GetComponent<Rigidbody>().AddTorque (Vector3.up * torque * moveHorizontal);
         GetComponent<Rigidbody>().AddTorque (Vector3.up * torque * moveVertical);    
     }
     void OnTriggerEnter(Collider other){
         if (other.gameObject.tag == "IceFloor") {
             GetComponent<Collider>().material.dynamicFriction = 0;
         }
     }
 
     void OnTriggerExit(Collider other){
         if (other.gameObject.tag == "IceFloor") {
             GetComponent<Collider>().material.dynamicFriction = 1;
             
         }
     }
 }
avatar image bojan1986819 · Mar 13, 2015 at 09:59 AM 0
Share

I changed the OnTriggerEnter to OnTriggerStay and removed the OnTriggerExit and now it is perfect!Thanks for helping out!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Simple 2D smooth ball movement 1 Answer

The ball is stuck in the beginning position 1 Answer

Rigidbody Movement 1 Answer

Ball Rolling System 1 Answer

The Physics of Ball Spin in Tennis, Topspin and Backspin 3 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