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 awplays49 · May 05, 2015 at 05:48 PM · directioniceslipping

How to make ice effect, or skidding car effect?

I want to make a moon game, but I am having trouble with making an effect that makes it hard to turn. This is an example of what should happen as the result:

1 The player moves forward and accelerates for an amount of time

2 The player turns sharp

3 The player keeps skidding in the previous direction, while gaining momentum in the new direction

Here's my code.

The GetAxis parts inside the WASD code is my attempt to make skidding.

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
 
     public float accelerationSpeed;
     public float decelerationSpeed;
     private float [] speed = new float [4];
     public float maxSpeed;
     private float mouseX;
     private float mouseY;
     public float xSensitiv;
     public float ySensitiv;
     public float jumpForce;
     private Vector3 [] lastDirection = new Vector3 [4];
     private Vector3 [] movement = new Vector3 [5];
     
     void FixedUpdate () {
         if (Input.GetKey (KeyCode.W))
         {
             speed [0] += accelerationSpeed * Time.deltaTime;
             speed [0] = Mathf.Clamp (speed [0], 0, maxSpeed);
             if (Input.GetAxis ("Mouse X") < 0.125f && Input.GetAxis ("Mouse X") > -0.125f)
             {
                 movement [0] = transform.forward * speed [0];
             }
             else
             {
                 movement [0] = lastDirection [0];
             }
         }
         else
         {
             speed [0] -= decelerationSpeed * Time.deltaTime;
             speed [0] = Mathf.Clamp (speed [0], 0, maxSpeed);
         }
         if (Input.GetKey (KeyCode.A))
         {
             speed [1] += accelerationSpeed * Time.deltaTime;
             speed [1] = Mathf.Clamp (speed [1], 0, maxSpeed);
             if (Input.GetAxis ("Mouse X") < 0.125f && Input.GetAxis ("Mouse X") > -0.125f)
             {
                 movement [1] = -transform.right * speed [1];
             }
             else
             {
                 movement [1] = lastDirection [1];
             }
         }
         else
         {
             speed [1] -= decelerationSpeed * Time.deltaTime;
             speed [1] = Mathf.Clamp (speed [1], 0, maxSpeed);
         }
         if (Input.GetKey (KeyCode.S))
         {
             speed [2] += accelerationSpeed * Time.deltaTime;
             speed [2] = Mathf.Clamp (speed [2], 0, maxSpeed);
             if (Input.GetAxis ("Mouse X") < 0.125f && Input.GetAxis ("Mouse X") > -0.125f)
             {
                 movement [2] = -transform.forward * speed [2];
             }
             else
             {
                 movement [2] = lastDirection [2];
             }
         }
         else
         {
             speed [2] -= decelerationSpeed * Time.deltaTime;
             speed [2] = Mathf.Clamp (speed [2], 0, maxSpeed);
         }
         if (Input.GetKey (KeyCode.D))
         {
             speed [3] += accelerationSpeed * Time.deltaTime;
             speed [3] = Mathf.Clamp (speed [3], 0, maxSpeed);
             if (Input.GetAxis ("Mouse X") < 0.125f && Input.GetAxis ("Mouse X") > -0.125f)
             {
                 movement [3] = transform.right * speed [3];
             }
             else
             {
                 movement [3] = lastDirection [3];
             }
         }
         else
         {
             speed [3] -= decelerationSpeed * Time.deltaTime;
             speed [3] = Mathf.Clamp (speed [3], 0, maxSpeed);
         }
         mouseX += Input.GetAxis ("Mouse X") * xSensitiv * Time.deltaTime;
         transform.rotation = Quaternion.Euler (0, mouseX, 0);
         mouseY -= Input.GetAxis ("Mouse Y") * ySensitiv * Time.deltaTime;
         mouseY = Mathf.Clamp (mouseY, -90, 90);
         Camera.main.transform.localRotation = Quaternion.Euler (mouseY, 0, 0);
         if (GetComponent <CharacterController> ().isGrounded == true)
         {
             movement [4] = Vector3.zero;
             if (Input.GetKey (KeyCode.Space))
             {
                 movement [4] = Vector3.up * jumpForce;
             }
         }
         else
         {
             movement [4] += Vector3.down * -Physics.gravity.y * Time.deltaTime;
         }
         GetComponent <CharacterController> ().Move ((movement [0] + movement [1] + movement [2] + movement [3] + movement [4]) * Time.deltaTime);
         lastDirection [0] = movement [0];
         lastDirection [1] = movement [1];
         lastDirection [2] = movement [2];
         lastDirection [3] = movement [3];
     }
 }
 
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 awplays49 · May 05, 2015 at 05:50 PM 0
Share

Also, I am not fixed on this code. I know there is probably a more efficient way to do this, so I don't necessarily have to keep this method.

1 Reply

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

Answer by HD32 · May 05, 2015 at 06:12 PM

I would use the default ice physics material. But it may not have the exact effect you are looking for.

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

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

How to create icy floor? c# 1 Answer

Rigidbody Movement 1 Answer

Change the direction of velocity upon tapping a button!!?? 1 Answer

Calculate weighted mean based on direction 0 Answers

How to push object in direction a player is facing C#? 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