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 sirofjava · Dec 19, 2017 at 07:06 PM · uimovement

issue with Virtual Joystick

Hello all

Kindly I facing 2 issues with my Virtual Joystick developed over unity5 , kindly I need your support to solve the issue where I have 2 Virtual Joysticks one for player moving (Gris color) and the second for camera (orange color) please see the following screenshoot: alt text

My issues as the following: 1- For the Virtual Joystick responsible about the player moving , the player object not rotate in the same direction of the Joystick pressed , its moving in all direction but not facing the same direction of the Joystick pressed . 2- The camera can see through the Terrain “ground ” how to prevent that.

The script im using from Virtual Joystick :
using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.EventSystems;

public class VirtualJoystick : MonoBehaviour,IDragHandler,IPointerUpHandler,IPointerDownHandler {

 private Image bgImg;
 private Image joystickImg;
 public Vector3 InputDirection{ set; get;}
 // Use this for initialization
 void Start () {
     bgImg = GetComponent<Image> ();
     joystickImg = transform.GetChild (0).GetComponent<Image> ();
     InputDirection = Vector3.zero;

 }

 // Update is called once per frame
 //void Update () {

 //}
 public virtual void OnDrag(PointerEventData ped)
 {
     Vector2 pos = Vector2.zero;
     if (RectTransformUtility.ScreenPointToLocalPointInRectangle
         (bgImg.rectTransform,
             ped.position,
             ped.pressEventCamera,
             out pos)) {
         pos.x=(pos.x/bgImg.rectTransform.sizeDelta.x);
         pos.y=(pos.y/bgImg.rectTransform.sizeDelta.y);
         float x=(bgImg.rectTransform.pivot.x==1) ? pos.x*2+1 : pos.x*2-1;
         float y=(bgImg.rectTransform.pivot.y==1) ? pos.y*2+1 : pos.y*2-1;
         InputDirection=new Vector3(x,0,y);
         InputDirection=(InputDirection.magnitude>1) ? InputDirection.normalized : InputDirection;

         joystickImg.rectTransform.anchoredPosition=
             new Vector3(InputDirection.x*(bgImg.rectTransform.sizeDelta.x/3),InputDirection.z*(bgImg.rectTransform.sizeDelta.y/3));
         Debug.Log(InputDirection);
     }

 }
 public virtual void OnPointerDown(PointerEventData ped)
 {
     OnDrag (ped);

 }
 public virtual void OnPointerUp(PointerEventData ped)
 {


     //Here is the problem it just goes to zero so fast so my character also moves so fast...how can i make it so motth
     InputDirection =Vector3.zero;
     joystickImg.rectTransform.anchoredPosition =Vector3.zero;
 }

}

The script im using for camera :

 using UnityEngine;
 using System.Collections;
 
 public class FreeCamera : MonoBehaviour {
     public Transform lookAt;
     public VirtualJoystick camerajs;
     private float distance = 200.0f;
     private float currentx = 0.0f;
     private float currenty = 0.0f;
     private float sensitivityx = 1.0f;
     private float sensitivityy = 1.0f;
     private void Update()
     {
         currentx += camerajs.InputDirection.x * sensitivityx;
         currenty += camerajs.InputDirection.z * sensitivityy;
     }
     private void LateUpdate()
     {
         Vector3 dir = new Vector3(0, 0, -distance);
         Quaternion rotation = Quaternion.Euler(currenty, currentx, 0);
         transform.position = lookAt.position + rotation * dir;
         transform.LookAt(lookAt);
     }
 } 

alt text

vj.jpg (51.6 kB)
main-camera.jpg (69.2 kB)
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
Best Answer

Answer by sirofjava · Jan 04, 2018 at 08:31 PM

this issue is solved after doing the following 1- Add plan instead of terrain 2- Remove the plan default collider 3- Add box collider to the plan 4- adding box collider to the target the issue related to camera raycast

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 franko-janku · Mar 04, 2018 at 11:40 PM 0
Share

thank you for this info :)

avatar image franko-janku · Mar 07, 2018 at 09:43 AM 0
Share

hey man i try to do what you said but it doesnt function in my project (i tried to do in a new project for testing and it was right as you said addding plan ins$$anonymous$$d of terrain but in my project main project it doesnt function even with plan :( Help pls

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

152 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 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

UI buttons to move character? 0 Answers

Having an issue blocking UI taps from passing through the UI into a gameobject. 3 Answers

Using UI buttons for Input Manager 0 Answers

How can I make the player stop moving when a UI dialogue box is active? 2 Answers

Unity 4.6 button movement problem 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