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 /
This question was closed Sep 12, 2015 at 04:15 AM by Darth_Cheree for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Darth_Cheree · Sep 12, 2015 at 12:00 AM · c# tutorial

Using the roll a ball tutorial my dart backs off the canvas

Hi, I am using the movement script from the roll a ball tutorial, but as soon as I start the game my dart backs off the canvas all by itself.

Here's the code I'm using;

 using UnityEngine;
 using System.Collections;
 
 public class PlayerMovement : MonoBehaviour {
     
     public float speed;
     
     private Rigidbody rb;
     
     void Start ()
     {
         rb = GetComponent<Rigidbody>();
     }
     
     void FixedUpdate ()
     {
         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
         
         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
         
         rb.AddForce (movement * speed);
     }
 }

Also, I want to use the arrow keys to move the dart left and right only, where would I need to put that script? In a new C# script or somewhere in this one possibly?

Any help would be totally appreciated :) Thanks

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

  • Sort: 
avatar image
0

Answer by Darth_Cheree · Sep 12, 2015 at 02:33 AM

This is my latest attempt to keep my dart only moving left and right.

using UnityEngine; using System.Collections;

public class moveDart_LR : MonoBehaviour {

 float speed = 1.0f;
 
 void Update() {
     if (Input.GetKey (KeyCode.RightArrow)) 
         transform.Translate(Vector2.right * Time.deltaTime);
     if (Input.GetKey (KeyCode.LeftArrow)) 
         Transform.Translate(Vector2.left * Time.deltaTime);
 }

}

Comment
Add comment · Show 1 · 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 Darth_Cheree · Sep 12, 2015 at 04:15 AM 0
Share

Ok so I am answering my own question here as I just found the answer. I took the sprite off of Interpolate and used this code to make the sprite move left and right using the arrow keys.

 using UnityEngine;
 using System.Collections;
 
 public class moveDart_LR : $$anonymous$$onoBehaviour {
     
     public float speed = 1.0f;
     
     void Start(){
     }
 
     void Update(){
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.RightArrow))
             transform.position += new Vector3 (speed * Time.deltaTime,0.0f,0.0f);
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.LeftArrow))
             transform.position -= new Vector3 (speed * Time.deltaTime,0.0f, 0.0f);
     }
 }

Follow this Question

Answers Answers and Comments

27 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

Related Questions

Why is this not working? 1 Answer

Enemy destroys player if scale is bigger 1 Answer

Saving data in a txt file from Input Field button? 0 Answers

A namespace can only contain types and namespace declarations..(39,14) 0 Answers

unity c# money system 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