首页 \ 问答 \ Raycast或时间或滞后?(Raycast or timing or lag?)

Raycast或时间或滞后?(Raycast or timing or lag?)

所以我正在从教程中对一个raycast物理处理程序进行测试。 我正在从每个模拟的相同高度下降一个块,目标是使块以平滑的方式落在平坦表面的顶部。 目前,我的光线投影通过皮肤宽度从盒子的底部突出,raylength缩小了velocity.y如下所示:

rayOrigin += Vector2.right * (verticalRaySpacing * i + velocity.x);
//Sends out the ray at its respective spot an length

RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.up * directionY, rayLength, collisionMask);
Debug.DrawRay(rayOrigin, Vector2.up * directionY * rayLength, Color.red);

//If the ray hits, make velocity = distance to the hit distance - skin width
//Also reset the rayLength for edge height discrepencies
if (hit)
{
    //Reports the very first hit.distance and velocity.y at the first hit
    if (!temp && hit.distance != 0)
    {
        Debug.Log(hit.distance);
        Debug.Log(velocity.y);
        temp = true;
    }

    velocity.y = (hit.distance - skinWidth) * directionY;
    rayLength = hit.distance;
}

我的问题是,当我反复运行这个模拟时,大约有一半的时间,当块与平面碰撞时,它会在表面上方产生这个初始的“停止力”,然后块上的重力重新启动并拉动它直接在表面上。

所以基本上,有时候它会在比其他时间更高的距离感应到碰撞,从而迫使它在太空中停止半空。 我已经通过观察hit.distancevelocity.y上的hit.distance映射了这一点。 这种不利影响发生的时间, hit.distance距离大于0.1velocity.y hit.distance大约是-9.56 ,而hit.distance距离有利的hit.distance0.1以下, velocity.y -9.67-9.67

当我根本不改变系统时,什么导致模拟高度和数字的差异? 是编辑中的滞后还是需要考虑的事情? 它会出现在移动应用程序上吗?

谢谢你的帮助。


So i'm running a test on a raycast physics handler from a tutorial. I am dropping a block from the same height each simulation with the goal to have the block land on top of a flat surface in one smooth motion. Currently, I have raycasts projecting out of the bottom of the box through a skin width with the raylength scaling off the velocity.y as seen below:

rayOrigin += Vector2.right * (verticalRaySpacing * i + velocity.x);
//Sends out the ray at its respective spot an length

RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.up * directionY, rayLength, collisionMask);
Debug.DrawRay(rayOrigin, Vector2.up * directionY * rayLength, Color.red);

//If the ray hits, make velocity = distance to the hit distance - skin width
//Also reset the rayLength for edge height discrepencies
if (hit)
{
    //Reports the very first hit.distance and velocity.y at the first hit
    if (!temp && hit.distance != 0)
    {
        Debug.Log(hit.distance);
        Debug.Log(velocity.y);
        temp = true;
    }

    velocity.y = (hit.distance - skinWidth) * directionY;
    rayLength = hit.distance;
}

My problem is that when i run this simulation over and over, about half the time when the block collides with the flat surface it produces this initial "stopping force" a bit above the surface, and then the gravity on the block restarts and pulls it directly onto the surface.

So basically, sometimes it is sensing a collision at higher distances than other times forcing it to stop mid-air too early. I have mapped this out by watching the Debug.Log on the hit.distance and velocity.y. The times where this unfavorable effect happens, the hit.distance is above 0.1 and the velocity.y is about -9.56, while the times that are favorable the hit.distance is somewhere below 0.1 and the velocity.y is -9.67.

What is causing this difference in the simulation heights and numbers when i am not changing the system at all? Is it lag in the editor or something that needs to be accounted for? Will it show up on a mobile App?

Thanks for your help.


原文:https://stackoverflow.com/questions/47257205
更新时间:2022-06-23 12:06

最满意答案

ActiveAdmin Sortable gem与资源,动作一起使用时

:sort

将添加到您的帖子的控制器。 我想你可以用

can(:sort, Post)

在ability.rb文件中。 您可能必须有条件地隐藏/显示可排序的句柄列。 我想你可以在索引部分这样做:

index do
  sortable_handle_column if can?(:sort, Post)
end

When using ActiveAdmin Sortable gem with a resource, an action

:sort

will be added to the controller for your Post. I think you can use

can(:sort, Post)

in the ability.rb file. You may have to conditionally hide/show the sortable handle column. I think you can do it this way in the index part:

index do
  sortable_handle_column if can?(:sort, Post)
end

相关问答

更多
  • 嗯,这是有效的: class Ability include CanCan::Ability def initialize(user) user ||= Admin.new # guest user (not logged in) if user.type == "Administrator" can :manage, Company elsif user.type == "Supervisor" can :manage, Company do ...
  • 问题出在.permit中,我不得不将它直接添加到create_params方法中。 class ApiController < ActionController::API def create_params params.require(controller_name.classify.downcase.to_sym).permit(self.class::PERMITTED_PARAMS) end end The problem was in the .permit, I had to ...
  • 改变这个想法: config.authorization_adapter = ActiveAdmin::CanCanAdapter config.cancan_ability_class = Ability authorization_adapter告诉活动管理员应该使用哪个适配器。 cancan_ability_class告诉适配器它应该使用哪个类。 如果仍然无效,请尝试将“ Ability重命名为“ AdminAbility 。 Change this thinks: config.authoriza ...
  • 我决定开发一个宝石来解决这个问题,它仍然在开发中,但很快就适合了。 它被称为CanCanCanSee。 看看这里 它为您提供CanCanCanSee.all_abilities方法,以呈现现有能力和角色的哈希值。 此外,如果你想从终端运行你的能力的漂亮印刷版本(想想你使用rake routes ),你有CanCanCanSee.pretty_print_abilities 谢谢! I have decided to develop a gem to solve this answer, it's still ...
  • 请看: SO问题 看看这一行: authorize_resource :class => false Please see this: SO Question Check out this line: authorize_resource :class => false
  • 将ActiveAdmin Sortable gem与资源,动作一起使用时 :sort 将添加到您的帖子的控制器。 我想你可以用 can(:sort, Post) 在ability.rb文件中。 您可能必须有条件地隐藏/显示可排序的句柄列。 我想你可以在索引部分这样做: index do sortable_handle_column if can?(:sort, Post) end When using ActiveAdmin Sortable gem with a resource, an act ...
  • 正如评论中所讨论的,你应该使用类似的东西 {:active => true, :closed => false, :sweep => { :disclosure => { :allusers => true } } } as discussed in the comments you should use something like {:active => true, :closed => false, :sweep => { :disclosure => { :allusers => true } } ...
  • 假设有has_many / belongs_to类型的assciation你可以很容易地这样做: can [:create, :read], ProjectQuestion do |project_question| can? :read, project_question.project end 请注意,在检查能力之前,您必须将project_id分配给新的project_question。 因此,在您的控制器/视图中,您无法做到 can? :create, ProjectQuestion.new ...
  • 检查表名。 它真的叫做“项目”,而不是“项目”吗? 你描述范围的方式有点奇怪。 例如,而不是where('closed =', 'false')我将其描述为where(closed: false) ,最小化SQL感知片段的数量 Check the table name. Is it really called "project", not "projects"? The way you describe scopes is a bit weird. E.g. instead of where('closed ...
  • 在深入研究代码后,我发现了正在发生的事情。 ActiveAdmin和它的CanCanAdapter还不兼容CanCanCan的check_authorization方法。 该方法依赖于授权方法在控制器上设置的@_authorized实例变量,但ActiveAdmin的授权不设置此变量。 因此,即使ActiveAdmin IS执行授权, check_authorization始终会失败,因为ActiveAdmin未设置此实例变量。 我已经报告了这个问题,但是现在的解决方法是将一个unless:子句添加到与所有 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)