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 CardDeath · Jan 27, 2015 at 05:36 PM · uivelocitydirectionplayer movementslider

4.6 UI Player Movement with Slider.

Hey there, I'm wanting the players velocity to be controls by a slider. However this may have to be done by using location rather than velocity. I'm pretty new to physics within unity and the new UI system like most people. This is my player movement script at the moment:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class Player : MonoBehaviour {
 
     private float moveSpeed = 20f;
     private int playerHitpoints = 3;
     private GameObject hitPartical;
     private GameObject deathPartical;
     private float hozInput;
 
     public GameObject[] healthIcons = new GameObject[3];
     
     Transform myTrans;
     Rigidbody myBody;
 
     // Use this for initialization
     void Start () {
         //Says memory.
         myTrans = this.transform;
         myBody = this.rigidbody;
 
         healthIcons [0].SetActive (true);
         healthIcons [1].SetActive (true);
         healthIcons [2].SetActive (true);
 
         deathPartical = (GameObject)(Resources.Load("Partical Systems/PS_Enemy_Dead"));
         hitPartical = (GameObject)(Resources.Load("Partical Systems/PS_Enemy_Hit"));
 }
     
     // Update is called once per frame
     void FixedUpdate () {
 
 
         //If it's not any one of these devices then keyboard controls will work.
 #if !UNITY_ANDROID && !UNITY_IPHONE && !UNITY_BLACKBERRY && !UNITY_WINRT
         //Calls the movement function and takes a float which is the Input.GetAxis short cut.
         Movement (Input.GetAxis ("Horizontal"));
 #else
         Movement (hozInput);
 #endif
 
 
     
     }
 
     void Movement(float horizontalInput)
     {
         //Stores the velocity in a V3.
         Vector3 moveVel = myBody.velocity;
         //The x axis is the value passed intimes by movespeed.
         moveVel.x = horizontalInput * moveSpeed;
         //The value from the v3 is stored back into velocity.
         myBody.velocity = moveVel;
     }
 
     public void StartMoving(float horizontalInput)
     {
         hozInput = horizontalInput;
     }


Im aware that this doesn't work because it simply takes a value in hozInput and will just set the velocity in 1 direction on the X axis. I need it to maintain the same velocity value but have it go from positive to minus in the X and have the player stop when the player stops sliding.

Any ideas?

Thank you.

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

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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Rigidbody Local Velocity 1 Answer

My player velocity changing by itself? 1 Answer

Rotation and Velocity of bullets. 1 Answer

Get the sin of an angle between vector3.forward and direction character is moving 1 Answer

Moving a ball in the opposite direction of where it hits 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