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.distance
和velocity.y
上的hit.distance
映射了这一点。 这种不利影响发生的时间,hit.distance
距离大于0.1
,velocity.y
hit.distance
大约是-9.56
,而hit.distance
距离有利的hit.distance
在0.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 thehit.distance
andvelocity.y
. The times where this unfavorable effect happens, thehit.distance
is above0.1
and thevelocity.y
is about-9.56
, while the times that are favorable thehit.distance
is somewhere below0.1
and thevelocity.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
最满意答案
将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 ...
-
如何在没有模型cancancan的情况下设置api资源的能力(how to set an ability for api resource without model cancancan)[2023-10-16]
请看: 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:子句添加到与所有 ...