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 martipello · Dec 09, 2015 at 10:24 PM · rotationtouch controlstilesconstantforce

beginners scripting problem using rotate and constant force

Unity beginner, First question, apologies for how wordy it is; i was folllowing a tutorial on youtube designing a pokemon-esque game, 2d tile built world with a character and script, playerStat.js and everything went well and works. I wanted to expand on this firstly by changing the way the character is controlled. What i want is a constant force that rotates exactly 90' on click or touch but only once per click or swipe, so i set about doing exactly that i added constant force to a rigidbody and added a rotate transform and it works... kind of.. right now the object keeps accelerating so i need to control the speed of the constant force or approach it a different way, and the rotation i have set at 180' as using 90' barely moved it at all but 360' in my script is still not enough to be 90' in the game, the camera is attached to the placeholder character and pressing 'a' or 'd' (my assigned keys) once will spin the character and camera about 70' and holding down those keys makes it spin longer whereas i need short 90' turn and holding down should do nothing. But the biggest mistake is that these scripts are seperate so playerStat.js has a way of walking across each tile as a single square and characterController script is just the left and right and i want to almost incorporate them both ive tried a few times to sort of merge them but i cannot make it work to make it worse one script (the tutorials script) is javascript and my script is in C# Maybe some body can help me i bet its not as hard as im making it out any advice appreciated

heres the js script player stat, it knows where the tiles are in my game and will walk 1 space at a time. so it doesnt pause to turn

    #pragma strict

  var startPoint : Vector3;
  var endPoint : Vector3;
  var speed : float;
  private var increment:float;
  var isMoving : boolean;

  function Start () {
 startPoint = transform.position;
 endPoint = transform.position;
 }

 function Update () {
 if(increment <=1 && isMoving == true){
     increment += speed/10;
     Debug.Log("Moving");
 }else{
     isMoving = false;
     Debug.Log("Stopped");
 }
 if(isMoving)
     transform.position = Vector3.Lerp(startPoint, endPoint,increment);

 if(Input.GetKey("w")&& isMoving == false){
     increment = 0;
     isMoving = true;
     startPoint = transform.position;
     endPoint = new Vector3(transform.position.x,transform.position.y,transform.position.z+1);
 }
 else if(Input.GetKey("s")&& isMoving == false){
     increment = 0;
     isMoving = true;
     startPoint = transform.position;
     endPoint = new Vector3(transform.position.x,transform.position.y,transform.position.z-1);
 }
 else if(Input.GetKey("a")&& isMoving == false){
     increment = 0;
     isMoving = true;
     startPoint = transform.position;
     endPoint = new Vector3(transform.position.x-1,transform.position.y,transform.position.z);
 }
 else if(Input.GetKey("d")&& isMoving == false){
     increment = 0;
     isMoving = true;
     startPoint = transform.position;
     endPoint = new Vector3(transform.position.x+1,transform.position.y,transform.position.z);
 }
 }

and this is the cs script just taking a left and right

 using UnityEngine;
 using System.Collections;

 public class characterController : MonoBehaviour {

 public int rotateSpeed = 180;

 // Use this for initialization
 void Start () {

     Rigidbody rb = GetComponent<Rigidbody>(); 
     rb.AddForce(0, 0, 0);
 }
 
 // Update is called once per frame

 void Update () {

     transform.Translate(Input.GetAxis("Horizontal") * Time.deltaTime, 0f, Input.GetAxis("Vertical") * 
     Time.deltaTime);
     transform.Rotate(0, Input.GetAxis("Rotate") * rotateSpeed * Time.deltaTime, 0);

 }
 }



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

35 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

Related Questions

Restrict second touch 0 Answers

Addforce to Z axis rotation via touch input/ mobile 0 Answers

Issues With Touch Rotation code 0 Answers

Smooth rotation with CrossPlatformInput 0 Answers

Rotate Player w/Touch Input Controls 0 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