Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Help and Support v
« Previous 1 … 15 16 17 18 19 … 21 Next »
Issue with applyForceOffset
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threaded Mode
Issue with applyForceOffset
28-04-2015, 10:02 PM, (This post was last modified: 28-04-2015, 10:12 PM by LocInt.)
#1
LocInt Offline
Long gone
****
Posts: 489
Threads: 91
Joined: Aug 2014
Issue with applyForceOffset
Hey,

For some reason starting today im getting this error:

Code:
sv: SF:starfall/loctech/lift.txt:204: Type mismatch (Expected Vector, got NaN at index 1) in function applyForceOffset

Line 204: I've been using PhysObj:applyForceOffset( Dir, Offset ). Dir and Offset come from calculations of applyTorque.

This issue wasnt here last night. Also applyForceOffset is acting weird.

тѕсм.Person8880 hovers the nerf bat over Tetryon damage
Website Find
Reply
29-04-2015, 05:48 PM,
#2
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Issue with applyForceOffset
You're getting the normalised version of a zero vector, i.e dividing by 0.

Somewhere in the torque code there's
off = off:GetNormal() * torqueamount * 0.5

local dir = ( tq:Cross( off ) ):GetNormal()
If off is the zero vector, or tq and off are the same vector (which causes the cross product to return the zero vector) you end up with nan, nan, nan. There's also the case of where tq is the zero vector which will also cause the problem.

Basically, check for:
if torqueamount == 0 then return end
-- carry on...

EDIT: Had more than a 2 second look. The only way you'd end up with 0 magnitude vectors below is if your input is zero. So just check for zero torque.
Find
Reply
29-04-2015, 06:39 PM, (This post was last modified: 29-04-2015, 06:43 PM by LocInt.)
#3
LocInt Offline
Long gone
****
Posts: 489
Threads: 91
Joined: Aug 2014
RE: Issue with applyForceOffset
(29-04-2015, 05:48 PM)Person8880 Wrote: You're getting the normalised version of a zero vector, i.e dividing by 0.

Somewhere in the torque code there's
off = off:GetNormal() * torqueamount * 0.5

local dir = ( tq:Cross( off ) ):GetNormal()
If off is the zero vector, or tq and off are the same vector (which causes the cross product to return the zero vector) you end up with nan, nan, nan. There's also the case of where tq is the zero vector which will also cause the problem.

Basically, check for:
if torqueamount == 0 then return end
-- carry on...

EDIT: Had more than a 2 second look. The only way you'd end up with 0 magnitude vectors below is if your input is zero. So just check for zero torque.

Want to explain why this started to happen just now not before? Seriously I don't have time to fix all my code everyday. Sorry for being so rude but I feel like fixing all my chips always when I come online.

тѕсм.Person8880 hovers the nerf bat over Tetryon damage
Website Find
Reply
29-04-2015, 06:44 PM,
#4
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Issue with applyForceOffset
(29-04-2015, 06:39 PM)LocInt Wrote: Want to explain why this started to happen just now not before? Seriously I don't have time to fix all my code everyday. Sorry for being so rude but I feel like fixing all my chips always when I come online.
It's a property of mathematics? You're passing a zero vector in, you're going to get garbage out. The error is just stopping you from wasting time with something that wouldn't work.
Find
Reply
29-04-2015, 06:45 PM,
#5
LocInt Offline
Long gone
****
Posts: 489
Threads: 91
Joined: Aug 2014
RE: Issue with applyForceOffset
(29-04-2015, 06:44 PM)Person8880 Wrote:
(29-04-2015, 06:39 PM)LocInt Wrote: Want to explain why this started to happen just now not before? Seriously I don't have time to fix all my code everyday. Sorry for being so rude but I feel like fixing all my chips always when I come online.
It's a property of mathematics? You're passing a zero vector in, you're going to get garbage out. The error is just stopping you from wasting time with something that wouldn't work.

It actually worked just fine before I got this error. Big Grin

тѕсм.Person8880 hovers the nerf bat over Tetryon damage
Website Find
Reply
29-04-2015, 06:52 PM,
#6
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Issue with applyForceOffset
(29-04-2015, 06:45 PM)LocInt Wrote: It actually worked just fine before I got this error. Big Grin
The point is to make you aware that you're doing something wrong, rather than silently failing. It "worked" before because when you passed in zero it did nothing.
Find
Reply
04-05-2015, 01:46 AM,
#7
LocInt Offline
Long gone
****
Posts: 489
Threads: 91
Joined: Aug 2014
RE: Issue with applyForceOffset
This issue seems to be back. I have all these

if(Torqueamount == 0)then return end

if(Offset:IsZero()) then return end

if(Dir:IsZero())then return end

but yet sv: SFConfusedtarfall/loctech/lift.txt:209: Type mismatch (Expected Vector, got NaN at index 1) in function applyForceOffset

Line 209: PhysObj:applyForceOffset( Dir, Offset )

тѕсм.Person8880 hovers the nerf bat over Tetryon damage
Website Find
Reply
04-05-2015, 09:08 AM,
#8
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Issue with applyForceOffset
Check your force amount, I bet it'll print out as something like #Q.NAND, which is Source's way of saying way too big.

Basically you're probably passing "infinite" force to it. Just clamp the amount of torque you're applying:
local MaxTorque = 5e6 --Who knows what a good max is, try them and see
local NewTorqueAmount = math.clamp( TorqueAmount, 0, MaxTorque )
if NewTorqueAmount == 0 then return end
if NewTorqueAmount ~= TorqueAmount then
Torque:Normalize()
Torque:Mul( NewTorqueAmount )
TorqueAmount = NewTorqueAmount
end
Find
Reply
« Next Oldest | Next Newest »


  • View a Printable Version
Forum Jump:


Users browsing this thread:
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.