• 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 SpaceSloth · Oct 15, 2012 at 03:09 PM · gameacceleration

Deceleration / Gliding of an object

Hey guys!

I'm making an isometric shooter from the 3rd view, and I'm having a little issue.

The spaceship has a LookAt script, so he constantly looks at the mouse. Now to make him move, I assigned the WASD keys, moving him relative to the position of the mouse.

That works, it's all good, but now I wish to add a little deceleration / gliding effect as if it was on ice.

I tried increasing the drag in the rigid body, but it doesn't work. My script is attached to a Null, which is the parent of the spaceship.

Here's my code

 using UnityEngine;
 using System.Collections;
 
 public class LookAt : MonoBehaviour {
 
 
     public float speed;
     public float moveSpeed;
     RaycastHit hit;
     Plane ground;    
     public GameObject spaceship;
     
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
         ground = new Plane(Vector3.up, transform.position);
         
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         
         float dist = 0.0f;
                 
         if(ground.Raycast(ray,out dist)){
             Vector3 clickPoint = new Vector3(ray.GetPoint(dist).x, transform.position.y, ray.GetPoint(dist).z);
             
             Quaternion targetRotation = Quaternion.LookRotation(clickPoint - transform.position);
             
             transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);
                         
             
             if(Input.GetButton("Forward")){
                 spaceship.transform.position += spaceship.transform.forward * moveSpeed * Time.deltaTime; 
                 
             }
             
             if(Input.GetButton("Backwards")){
                 spaceship.transform.position += spaceship.transform.forward * -1 * moveSpeed * Time.deltaTime;
                         
             }
             
             if(Input.GetButton("Right")){
                 transform.Translate(new Vector3(0.15f, 0, 0));
             }
             
             if(Input.GetButton("Left")){
                 transform.Translate(new Vector3(0.15f * -1, 0, 0));
             }
             
         }
     }
 }

Now what should I do? Thanks for your answers in advance, preferably in C# :)

Comment
Add comment · Show 5
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 Fattie · Oct 15, 2012 at 03:12 PM 0
Share

hola - to be clear, are you familiar with AddForce?

that's how you move things around in a physics engine.

you mention you ARE using a rigidbody?

then Im afraid completely eli$$anonymous$$ate all code that translates or moves him, heh! that's for animating objects. simply "AddForce" and look at him go. to slow him down or whatever add force the other way.

it's great enjoy ! sorry if this is not what you're asking

avatar image SpaceSloth · Oct 15, 2012 at 03:23 PM 0
Share

Hey! No I wasn't really familiar with it haha.

I was using a rigidbody, but to no real avail or purpose.

I tried using addforce, but the problem is it completely messes up my look at, since it makes the rigidbody move, and not the empty game object I added the script to.

It also doesn't make him move in the direction of the mouse, rather in the general x axis.

I think it would be more complicated for me to rethink the whole thing, rather than cheating a little in fabricating a deceleration over time. I just need to figure out how :D

Thanks for your answer anyways!

avatar image Fattie · Oct 15, 2012 at 03:40 PM 0
Share

Well ... ok dude. Have fun.

It's really a shame because you're missing the whole point of a physics engine eh! :)

it makes it incredibly easy for you later.

$$anonymous$$gest you delete the rigidbody. All the best!

avatar image Fattie · Oct 15, 2012 at 03:40 PM 0
Share

PS you need unitygems.com

avatar image SpaceSloth · Oct 15, 2012 at 03:42 PM 0
Share

It's only for a school project, I will indeed use it later :D

Thanks for the site! I'll definitely check it out :) All the best

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

getting udp package info inside unity (GlovePIE) 0 Answers

Gliding vs bad acceleration dilema 0 Answers

Help with a gun script used in the fps tutorial 1 Answer

AI Slowing Down Game 0 Answers

Changing Booleans Throught Certain Distance 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