- Home /
rigid body can rotate but will not move
Hello Unity forums (: I am trying to build a vuforia AR game. I followed this guide: https://www.youtube.com/watch?v=khavGQ7Dy3c And succeeded in making it fully functional, with the character walking around(using .velocity) and rotating to face the direction it moves in(using .transform.eulerAngles). However, once I swapped out the character model for a different model(In my case, a beating heart), the replacement model could still move around but could no longer rotate. I tried changing the model scale (.transform.localScale) but that didnt work either. It seems that the rb.velocity still functions normally but not the rb.transform.localScale or rb.transform.eulerAngles methods. I remembered to attach a rigid body component to the new model and also to drag them into the appropriate inspector boxes. Please send help i am out of ideas. Here is my code, just in case yall wanna look at it. Note that there are some really lame questionable things I did in the code like converting a byte into a string then into an int then into a float. But for now I need to solve the most pressing issue which is the transform not working.
thank you so much for your help ((':
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class overseer : MonoBehaviour
{
public Text txt;
public GameObject character;
public GameObject SpawnPoint;
public GameObject Plane;
public Rigidbody rb;
public Animation anim;
byte[] BLEin = new byte[4]{0,0,0,0};
int inInt;
float inFloat;
string inString;
public textChanger00 textChanger00;
float x = 0;
float y = 0;
// float z = 0;
float angle;
// Start is called before the first frame update
void Start()
{
rb = character.GetComponent<Rigidbody>();
anim = character.GetComponent<Animation>();
textChanger00 = GameObject.FindObjectOfType<textChanger00>();
// character.transform.position = new Vector3(0f,1f,-6f);
// rb.transform.position = new Vector3(0f,0f,0f);
}
void FixedUpdate()
{
Vector3 movement = new Vector3 (x,-0.05f,y);
rb.velocity = movement * 4f;
}
// Update is called once per frame
void Update()
{
BLEin = textChanger00.getBytes();
//inFloat = System.BitConverter.ToSingle(BLEin,0);
//inInt = System.BitConverter.ToInt32(BLEin,0);
//Debug.Log(System.BitConverter.getBytes(BLEin));
//inInt = int.Parse(BLEin);
//txt.text = System.Convert.ToBase64String(textChanger00.getBytes());
// txt.text = Encoding.Default.GetString(textChanger00.getBytes());
// txt.text = System.BitConverter.ToString(textChanger00.getBytes()); //works!
// txt.text = System.BitConverter.ToString(BLEin); // this also works
inString = System.BitConverter.ToString(BLEin);
inInt = System.Int32.Parse(inString, System.Globalization.NumberStyles.HexNumber); // aw shit this works. its stupid but it works
inFloat = inInt/10;
//txt.text = inString;
//Debug.Log(inInt);
//TEST CODE START HERE
// Vector3 scale = new Vector3 (inFloat,inFloat,inFloat);
// rb.transform.localScale = scale;
//TEST CODE END HERE
//okay so this works. the in the byte array, when working from 0 to 5, only 0th index changes
switch (BLEin[0])
{
case 1:
txt.text = "UP";
y = 1;
x = 0;
angle = 0;
// anim.Play("walk");
break;
case 2:
txt.text = "DOWN";
y = -1;
x = 0;
angle = 180;
// anim.Play("walk");
break;
case 3:
txt.text = "LEFT";
x = -1;
y = 0;
angle = -90;
// anim.Play("walk");
break;
case 4:
txt.text = "RIGHT";
x = 1;
y = 0;
angle = 90;
// anim.Play("walk");
break;
case 5:
txt.text = "A";
break;
case 6:
txt.text = "B";
x = 0;
y = 0;
break;
default:
txt.text = " ";
x = 0;
y = 0;
// anim.Play("idle");
// rb.velocity = Vector3.zero;
// rb.Sleep();
break;
}
Vector3 movement = new Vector3 (x,0,y); // no y component because not moving up and down
rb.velocity = movement * 4f;
rb.transform.eulerAngles = new Vector3(0,angle,0);
if (rb.transform.position.y < Plane.transform.position.y - 2)
{
rb.transform.position = SpawnPoint.transform.position;
}
}
}
Try throwing in some debug.log statements to figure out what parts of your code are actually being executed