Simple transform.Translate code not working
Hi so I'm a little rusty with Unity and started following NoobTuts snake tutorial, its a little old but still in Unity 5 so there souldn't be too many problems with the code. There's a simple transform.Translate section that I can't figure out why it isn't working.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class Snake : MonoBehaviour {
// Current Movement Direction
// (by default it moves to the right)
Vector2 dir = Vector2.right;
// Use this for initialization
void Start () {
// Move the Snake every 300ms
InvokeRepeating("Move", 0.3f, 0.3f);
}
// Update is called once per frame
void Update () {
}
void Move() {
// Move head into new direction
transform.Translate(dir);
}
}
This code is attached to a kinematic block, and is supposed to move the block one unit to the right every 0.3 seconds (after waiting 0.3 seconds from the start of the game). For the life of me I can't see what's wrong with this.
Any help would be appreciated guys.
Answer by TonyLi · Jun 29, 2017 at 03:04 PM
To keep your kinematic rigidbody in sync with your transform, use Rigidbody.MovePosition() or Rigidbody.position instead of Transform.Translate.
Your answer
Follow this Question
Related Questions
How can I make this character move smoothly? 1 Answer
My transform its moving but it makes Instantiate in one place 0 Answers
3D Player Controller Movement won't face it's head in the direction of the arrow key press 0 Answers
Any code to move diagonally like vector3.forward for moving forward? 1 Answer
Transform.Translate not moving in the direction of specified vector 2 Answers