Vector Math Error

Bug reports for the different beta versions of transcendence.
Post Reply
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

As a workaround for the inability to adjust the velocity of a type="particles" weapon I put together some vector functions to add the firing ship's velocity before calling syscreateweaponfire rather than after.

The problem is with this one.

Code: Select all

(setq AU_calcFireAngle (lambda (source gunAngle speed)
	(block (unitvector objvel shotvectorcomponent)
		(setq objVel (objGetVel Source))
		(setq unitvector (sysvectordivide (sysvectorpolaroffset nil gunAngle 1) 100))
		(setq shotvectorcomponent (sysvectormultiply unitvector speed))
		(sysvectorangle (sysvectoradd objvel shotvectorcomponent))
	)
))
This works except in the case that the shot is being fired "east," in which case shotVectorComponent is rotated 90 degrees to point "north."

The error can't be in sysVectorAngle because the horizontal component of objvel is correct. I think it can't be in sysVectorAdd for the same reason.
Literally is the new Figuratively
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Atarlost wrote:As a workaround for the inability to adjust the velocity of a type="particles" weapon I put together some vector functions to add the firing ship's velocity before calling syscreateweaponfire rather than after.

The problem is with this one.

Code: Select all

(setq AU_calcFireAngle (lambda (source gunAngle speed)
	(block (unitvector objvel shotvectorcomponent)
		(setq objVel (objGetVel Source))
		(setq unitvector (sysvectordivide (sysvectorpolaroffset nil gunAngle 1) 100))
		(setq shotvectorcomponent (sysvectormultiply unitvector speed))
		(sysvectorangle (sysvectoradd objvel shotvectorcomponent))
	)
))
This works except in the case that the shot is being fired "east," in which case shotVectorComponent is rotated 90 degrees to point "north."

The error can't be in sysVectorAngle because the horizontal component of objvel is correct. I think it can't be in sysVectorAdd for the same reason.
Try a few things:

1. Instead of (sysVectorPolarOffset nil gunAngle 1), try:

Code: Select all

(sysVectorPolarVelocity gunAngle 1)
The units for velocity are not the same as the units for distance; this will keep the units consistent.

2. Obviously, a gunAngle of 0 is to the right [x = cos(0), y = sin(0)] and 90 is straight up. I presume you're using the ship's current rotation for gunAngle?

3. Is there a specific set of inputs that fails? Can you tell me the inputs so I can try it? Or, alternately, could you include the whole extension so I can try it?
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

Even odder it's not the straight right shot that's failing (as I would have expected since I'd expect a zero vector component to be the culprit) it's the shot at -4 (86 degrees if 0 is up on the screen). Files have been emailed.
Literally is the new Figuratively
PM
Fleet Admiral
Fleet Admiral
Posts: 2570
Joined: Wed Sep 01, 2010 12:54 am

Is the angle negative? The game cannot handle those. Try adding 360 (to make it positive).
Download and Play in 1.9 beta 1...
Drake Technologies (Alpha): More hardware for combat in parts 1 and 2!
Star Castle Arcade: Play a classic arcade game adventure, with or without more features (like powerups)!
Playership Drones: Buy or restore exotic ships to command!

Other playable mods from 1.8 and 1.7, waiting to be updated...
Godmode v3 (WIP): Dev/cheat tool compatible with D&O parts 1 or 2.
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

No, I'm pretty sure it's 90-4 or 86. Unless the 0 angle isn't where I think it is. In any case the next facing counterclockwise had one shot firing just one more degree counterclockwise and no issues.

It's possible it's also failing at 87 and 88 since those angles weren't used by the weapon that revealed the bug.
Literally is the new Figuratively
User avatar
sun1404
Militia Captain
Militia Captain
Posts: 527
Joined: Thu Nov 03, 2011 10:32 am
Location: Heretic. (Finally!)

I think it's really bugged. I used Excalibur Targeting Software mod, and when I activate the version 2 software, which will point at wherever you need to shoot to hit your currently targeted ship, the reticules are placed haphazardly. Only when I'm precisely left or right of the target will the reticules become normal. This mod worked in 1.1 version.
Yes, look at my avatar, I have a wyvera type ship.
PM
Fleet Admiral
Fleet Admiral
Posts: 2570
Joined: Wed Sep 01, 2010 12:54 am

0 is east, 90 is north, 180 is west, 270 is south.
Download and Play in 1.9 beta 1...
Drake Technologies (Alpha): More hardware for combat in parts 1 and 2!
Star Castle Arcade: Play a classic arcade game adventure, with or without more features (like powerups)!
Playership Drones: Buy or restore exotic ships to command!

Other playable mods from 1.8 and 1.7, waiting to be updated...
Godmode v3 (WIP): Dev/cheat tool compatible with D&O parts 1 or 2.
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

A few things to try:

1. You should definitely use sysVectorPolarVelocity instead of sysVectorPolarOffset. It's a lot easier to create a velocity vector that way and I believe you can simplify AU_calcFireAngle to something like:

Code: Select all

(setq AU_calcFireAngle (lambda (source gunAngle speed)
        (sysvectoradd
              (objGetVel Source)
              (sysvectorpolarvelocity gunAngle speed)
         )
))
[If necessary, you can adjust by using sysvectordivide or sysvectormultiply as appropriate.]

2. The call to AU_calcFireAngle is getting a negative angle (gunAngle = -4). Unfortunately, sysVectorPolarOffset does not handle negative angles correctly (I've fixed that in the next RC). To work around it, try this:

Code: Select all

(setq AU_calcFireAngle (lambda (source gunAngle speed)
        (sysvectoradd
              (objGetVel Source)
              (sysvectorpolarvelocity (modulo 'degrees gunAngle 360) speed)
         )
))
The extra modulo call (with the 'degrees option) will correctly convert a -4 angle to 356. [Don't forget to change AU_calcFireSpeed as well.]
Post Reply