- Home /
arrows in unity 3d?
Hi all, In my project scene when i drag a object(sphere/ball) i want to show acceleration and velocity directions. so to do that i make an arrow asset and also one arrow texture.
And this is my drag option code
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(MeshCollider))]
public class GizmosController : MonoBehaviour
{
private Vector3 screenPoint;
private Vector3 offset;
void OnMouseDown()
{
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
void OnMouseDrag()
{
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}
}
so please tell me where can call acceleration and velocity arrows in my code? please help me i struck since last 3 days.... thanks to all
Please use the link on the right of the page to view the tutorial video which will tell you how to write a good question.
What you have here is a beginning, but you have a lot of work to do to get arrows for acceleration and velocity. Since you are not using the Physics engine, you will need to calculate the velocity yourself. You may need some sort of sample rate. If you just just sampled frame to frame, I would expect velocity and acceleration to vary a great deal, resulting in arrows that wildly change directions.
As for displaying the arrows themselves, one way would be to put textures of arrows on planes and rotate, scale and position the textures based on the readings you generate.