Skip to content

Instantly share code, notes, and snippets.

@takoyakiroom
Last active September 12, 2020 12:36
Show Gist options
  • Save takoyakiroom/4a158db5131fd89e0f7d023a7e7d6dfd to your computer and use it in GitHub Desktop.
Save takoyakiroom/4a158db5131fd89e0f7d023a7e7d6dfd to your computer and use it in GitHub Desktop.
Walkable
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Walkable : MonoBehaviour
{
public Transform head;
public Transform bodyCollider;
// Start is called before the first frame update
void Start()
{
// ヘッドセットのある位置に合わせてPlayerの初期位置を移動
Vector3 pos = transform.position;
pos.x -= head.transform.localPosition.x;
pos.z -= head.transform.localPosition.z;
pos.y = transform.position.y;
transform.position = pos;
}
// Update is called once per frame
void Update()
{
// Playerの高さをBodyColliderに合わせる
if (bodyCollider != null)
{
Vector3 pos = transform.position;
pos.y = bodyCollider.transform.position.y;
transform.position = pos;
}
}
void LateUpdate()
{
//bodyColliderのlocalPositionがPlayerからずれているので"0"に戻す
Vector3 local_pos = bodyCollider.transform.localPosition;
local_pos.y = 0f;
bodyCollider.transform.localPosition = local_pos;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment