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 /
  • Help Room /
avatar image
0
Question by Zanteous · Sep 01, 2015 at 08:46 PM · movementacceleration

Movement with acceleration problems

Hello, I'm new to Unity and only took a C course about 4 years ago so I'm kinda new to this. I'm trying to make a character to move around using physics and a code ocurred to me:

using UnityEngine;

using System.Collections;

public class Movement : MonoBehaviour

{ // Use this for initialization

 Vector3 acel, vel, v0 = Vector3.zero;
 float t,x,y,z,x0,y0,z0=0, max_vel=10;
 // float mass = 1;
 void Start ()
 {
 }
 // Update is called once per frame
 void Update ()
 {
     Repositioning();
 }

 void Repositioning()
 {
     t += Time.deltaTime;
     if (Input.GetKey(KeyCode.D))
     {
         acel=Vector3.right;
     }
     if (Input.GetKey (KeyCode.A))
     {
         acel=-Vector3.right;
     }
     while (vel.magnitude < max_vel)
     {
         vel = acel*t + v0;
         v0=vel;
     }
     x = acel.x*Mathf.Pow(t,2) / 2 + x0;
     x0 = x;
     y = acel.y*Mathf.Pow(t,2) / 2 + y0;
     y0 = y;
     z = acel.z*Mathf.Pow(t,2) / 2 + z0;
     z0 = z;
     transform.Translate(x, y, z);
 }

}

My Unity editor crashes after I add this Script as a component to a Sprite and try to run it to check if it works, though the compiler tells me there are no errors. Help? Pretty Please?!

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 D3Duck · Sep 01, 2015 at 08:54 PM

To me it looks like your while loop is infinite. What is the value of t while first running it? I'm not sure but might be 0,=. Thus your while look will never break out and you are forever stuck in frame 1.

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 Zanteous · Sep 02, 2015 at 01:58 AM 0
Share

It sure seems that I need a break there. Thanks.

avatar image D3Duck · Sep 02, 2015 at 10:05 AM 0
Share

Shouldnt that just be an if statement ins$$anonymous$$d?Did you fix the problem?

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

Cumulative acceleration for copies. 0 Answers

FPSController - Smooth Movement 0 Answers

Numbers not matching up on journey between two points 0 Answers

How to Limit or Remove Acceleration with RigidBody2D? 1 Answer

Trouble with button accelerate on face, simulate car 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