- Home /
Question by
JeffreyRocks · Feb 07, 2018 at 02:08 PM ·
rigidbodypositionvuforia
Find location of rigidbody within model.
I have AR Unity/Vuforia application with 2 targets and 2 models. 1 model is static (orc) and 1 model i can move around using MobileSingleStickcontrol (Orc_Wolfrider). this all works fine.
I move the orcwolfrider model using:
rb = GetComponent<Rigidbody>();
float x = CrossPlatformInputManager.GetAxis("Horizontal");
float y = CrossPlatformInputManager.GetAxis("Vertical");
Vector3 movement = new Vector3(x, 0, y);
rb.velocity = movement / 10;
The challenge: I want the orc model to move towards the Orc_Wolfrider. Both models have rigidbodies attached to them.
I tried attaching this script to the Orc_Wolfrider:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OrcController : MonoBehaviour {
private Rigidbody rigidbodyOrc;
private GameObject gameobject;
private Rigidbody rigidbodyWolfRider;
// Use this for initialization
void Start () {
rigidbodyOrc = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
gameobject = GameObject.Find("Orc_Wolfrider");
rigidbodyWolfRider = gameobject.GetComponent(typeof(Rigidbody));
var heading = rigidbodyWolfRider.position - rigidbodyOrc.position;
}
}
Does not seem to work. Does anyone know why?
Comment