Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 unity_PM96A4-pjeC-4Q · Dec 26, 2017 at 06:10 PM · transformmobilecontrollerrigidbody2drewriting

Rewriting movement on tranform to Rigidbody2D

Hi! I have this player controls made with transform, but unfortunately I'm very new to code and can't work further without Rigidbody2D. So I need to rewrite this transform controls to Rigidbody2d! Code at pastebin : https://pastebin.com/CKQ1JySx using System; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using UnityStandardAssets.CrossPlatformInput; public class PlayerMovement : MonoBehaviour { public float verticalInputAcceleration = 1; public float horizontalInputAcceleration = 1; public float maxSpeed = 1; public float rotationSpeed = 1; public float acceleration = 1; public float velocityDrag = 1; //public Vector3 velocity; private float zRotationVelocity; private Vector3 velocity; private void Update() { // apply velocity drag velocity = velocity * (1 - Time.deltaTime * velocityDrag); // clamp to maxSpeed velocity = Vector3.ClampMagnitude(velocity, maxSpeed); // update transform transform.position += velocity * Time.deltaTime; } private void FixedUpdate() { Vector3 direction = new Vector3(CrossPlatformInputManager.GetAxis("Horizontal") * horizontalInputAcceleration, CrossPlatformInputManager.GetAxis("Vertical") * verticalInputAcceleration, 0 ); bool move = !(Mathf.Approximately (direction.x, 0) && Mathf.Approximately (direction.y, 0)); if (move) { float angle = Mathf.Atan2 (direction.y, direction.x) * Mathf.Rad2Deg; Quaternion rotation = Quaternion.AngleAxis (angle - 90, Vector3.forward); transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime * rotationSpeed); velocity += transform.up * Mathf.Max(Mathf.Abs(direction.x), Mathf.Abs(direction.y)) * Time.deltaTime * 0.1f * acceleration; } } }

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

Answer by BOB_KSE · Dec 26, 2017 at 07:08 PM

Is this the standard assets 2d Character-Controller code? Anyway its hard to understand if you are new to Unity/Coding. You can use this 2D platformer code I made a while back. it uses Rigidbody2D and uses frame by frame movement instead of using axis. It will work on unity 2017. Hope this helps you...

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

122 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 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 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 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 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 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 avatar image avatar image

Related Questions

Change position of camera on scene load? 1 Answer

Is this a bug or am I using transform.up wrong? 3 Answers

How to rotate a rigidbody relative to another? 1 Answer

2D Lock x Axis on character 0 Answers

MMD How to export model and animations to Unity as 3rd person controller? 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