Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

備忘録的なやつ

More than 3 years have passed since last update.
Arrow.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Arrow : MonoBehaviour {

    [SerializeField]
    Rigidbody r;

    [SerializeField]
    Transform left;

    [SerializeField]
    Transform right;

    [SerializeField]
    Transform left2;

    [SerializeField]
    Transform obj;

    float speed = -1f;


    void Update(){
        //CirclarMotion ();
        ElliptiicalMotionBy2Points();
    }

    //2点間を直径とする正円運動
    void CirclarMotionByDiameter(){
        //cosθ = a(底辺)/c(斜辺)
        //a = c*cosθ
        //a = radius*cosθ

        //sinθ = b(高さ)/c(斜辺)
        //b = c * sinθ;
        //b = radius * sinθ

        //円の中心
        Vector3 a = left.position;
        Vector3 b = right.position;
        Vector3 center = new Vector3 ((a.x + b.x) / 2, (a.y + b.y) / 2, (a.z + b.z) / 2);

        //円の半径
        float radius = Vector3.Distance (a, center);
        float c = Time.time * speed;
        float x = radius * Mathf.Cos (c);
        float y = radius * Mathf.Sin (c);
        obj.position = new Vector3 (x, y, obj.position.z) + center;
    }

    //2点を通る楕円運動
    void ElliptiicalMotionBy2Points(){
        Vector3 a = left2.position;
        Vector3 b = right.position;
        Vector3 center = new Vector3 (a.x , b.y, (a.z + b.z) / 2);

        //円の半径
        float radiusX = Vector3.Distance (b, center);
        float radiusY = Vector3.Distance (a, center);

        float c = Time.time * speed;
        float x = radiusX * Mathf.Cos (c);
        float y = radiusY * Mathf.Sin (c);

        obj.position = new Vector3 (x, y, obj.position.z) + center;

    }

    //3点を通る正円運動
    void CirclarMotionBy2Points(){
        //中心(a,b)の円の半径を求める式は
        //(x-a)^2 + (y - b)^2 = r^2
        //これを一般形にすると、(aとbになんでもいいから入れるとわかる)
        //x^2 + y^2 +lx + my + n = 0
        //となるので、まず3点を定義する
        //とやろうと思ったけどプログラムで連立方程式なんてできるの。。。?

        //なので、
        //中心をO(x,y)とすると、OA=OB=OCであるので、

        Vector3 a = left2.position;
        Vector3 b = right.position;
        Vector3 c = left.position;




    }
}

ozawachev
Unityが好きです。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away