- Home /
There is a way to track an objects in a live feed of a webcam in Unity?
Hi, in my project i need to track an object in the live feed of a webcam(PS EYE) and get his x and y while it is moved. Anyone knows a way to track objects in Unity?
Thanks.
Answer by fueldown · Jul 02, 2013 at 06:31 PM
I think you should look into Vuforia. Sounds like a job for AR SDK.
How do I make a player shoot right and left 2D platformer firing left and right, help! using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityStandardAssets.CrossPlatformInput;
public class movo : $$anonymous$$onoBehaviour
{
float bulletSpeed = 500f;
public Animator anim;
public Transform barrel;
public Rigidbody2D bullet;
private Rigidbody2D rb;
private bool moveLeft;
private bool moveRight;
private float horizontal$$anonymous$$ove;
public float speed = 5;
public SpriteRenderer sp;
private void Start()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
sp = GetComponent<SpriteRenderer>();
moveLeft = false;
moveRight = false;
}
public void PointerDownLeft()
{
anim.SetBool("run", true);
moveLeft = true;
}
public void PointerUpLeft()
{
anim.SetBool("run", false);
moveLeft = false;
}
public void PointerDownRight()
{
anim.SetBool("run", true);
moveRight = true;
}
public void PointerUpRight()
{
anim.SetBool("run", false);
moveRight = false;
}
void Update()
{
$$anonymous$$ovementPlayer();
if (CrossPlatformInput$$anonymous$$anager.GetButtonDown ("Fire1"))
Fire ();
}
void $$anonymous$$ovementPlayer()
{
if (moveLeft)
{
sp.flipX = true;
horizontal$$anonymous$$ove = -speed;
}
else if (moveRight)
{
sp. flipX = false;
horizontal$$anonymous$$ove = speed;
}
else
{
horizontal$$anonymous$$ove = 0;
}
}
private void FixedUpdate()
{
rb.velocity = new Vector2(horizontal$$anonymous$$ove, rb.velocity.y);
}
void Fire()
{
var firedBullet = Instantiate (bullet, barrel.position, barrel.rotation);
firedBullet.AddForce (barrel.up * bulletSpeed);
}
}
Please do not post questions as comments especially if they are unrelated to the original post. Open a new question instead...
Also please provide information on what's not working. Just saying: "Here is my script and i want it to do X, modify it for me please" is not a good approach.
Your answer
Follow this Question
Related Questions
Whats the best way to colour? 1 Answer
spawn road 0 Answers
how to create a smooth curve with no edges 0 Answers
How to Enable unity with webcam efficently 1 Answer
how to check if webcam is used by another application 0 Answers