使用RotateAround旋转对象并为其设置限制

时间:2019-04-01 11:58:58

标签: c# unity3d

我的场景中有一个可以通过鼠标滑动来旋转( RotateAround )的对象。我想给对象一些旋转限制,例如X轴的-45度和45度,因此当它的旋转变为45度时,它不能超出它。

因此,当您看到波纹管时,我在脚本中尝试了 Mathf.Clamp 方法,并且该方法在Y轴上工作正常,该对象绕其X轴旋转且未超出Y限制。但是在X轴上,当对象的Y旋转达到O时,它会随着奇怪的旋转立即变为30度!你能告诉我我的代码有什么问题吗?

旋转脚本:

# -*- coding: utf-8 -*-

import datetime
import calendar
calendar.setfirstweekday(calendar.SUNDAY)

from odoo import models, fields, api

class HrMission(models.Model):
    _name = "hr.employee.mission"
    _description = "hr mission"
    _inherit = "hr.employee.mission"

    days_compensation =fields.Float(compute='get_compensation', compstring='Jours de récupération', help="Jours de récupération si la mission contient les jours de repos",
                             required=True, readonly=True,)

    @api.multi
    @api.depends('mission_start_date', 'mission_end_date')
    def get_compensation(self):
        for rec in self:
            if rec.mission_start_date and rec.mission_end_date:
                time1 = datetime.datetime.strptime(rec.mission_start_date, "%Y-%m-%d")
                time2 = datetime.datetime.strptime(rec.mission_end_date, "%Y-%m-%d")
                week = {}
                leave_value = {}
        # Compute Number Of Friday And Saturday
                for i in range((time2 - time1).days):
                    day = calendar.day_name[(time1 + datetime.timedelta(days=i+1)).weekday()]
                    week[day] = week[day] + 1 if day in week else 1                    
                fri = week.get('Friday') if 'Friday' in week else 0  # Result Number 1 Of friday If "Start Date", "End date" --> "02/04/2019", "07/04/2019"
                sat = week.get('Saturday') if 'Saturday' in week else 0 # Same thing that Friday, Numbre 1 for Saturday
                friandsat = fri + sat # Result 2
                rec.days_compensation = friandsat

1 个答案:

答案 0 :(得分:0)

在编辑器中,旋转值介于-180至180之间,但在transform.eulerAngles中,旋转值实际上介于0至360之间。

因此,在夹紧之前需要调整角度值。

if(angles.y > 180)
{
    angles.y -= 180f;
}

angles.y = Mathf.Clamp(angles.Y, minY, maxY);