Math and scripting

Post » Fri Jun 17, 2011 5:42 am

So I'm creating a script where I move a ref in front of the camera (only works in FP atm), and for this I decided to use a unit-circle-ish approach. (the ref fires a laserbeam towards the crosshair)
Now, it has been some time since I last worked with these circles, I think there was something about converting all coordinated into the first quadrant (multiply or subtract x*Pi), but I can't remember, however I remember the function:

x = r * cos alphay = r * sin alpha

I don't know if the game is set to degrees or radians though...
Well I tryed to use that in my scipt and got this:

set playeranglez to (player.getangle z)set playeranglex to (player.getangle x)	set playerposx to (5 * cos playeranglez)	set playerposy to (5 * sin playeranglez)	shooter.moveto player playerposx playerposy 110	shooter.setangle x playeranglex		shooter.FireWeapon WeapLaserRifle

This SHOULD in my mind, create a circle around the player with a radius of 5... HOWEVER in the second and fourth quadrant the point is behind the player, which means I've done something wrong, obviously... I did try to change the index of these quadrants, but to my supprise it gave the same result. That's what made me give up...

If anyone have another way to do this, or know what's wrong with my script I'd be VERY happy if anyone could tell me!

Kevin
User avatar
benjamin corsini
 
Posts: 3411
Joined: Tue Jul 31, 2007 11:32 pm

Post » Fri Jun 17, 2011 1:17 pm

Totally my bad...

The working script is OF COURSE: :facepalm:
set playeranglez to (player.getangle z)set playeranglex to (player.getangle x)        set playerposx to (5 * sin playeranglez)        set playerposy to (5 * cos playeranglez)        shooter.moveto player playerposx playerposy 110        shooter.setangle x playeranglex                shooter.FireWeapon WeapLaserRifle


Still, if there's a better way to do this, do tell ;)
User avatar
Theodore Walling
 
Posts: 3420
Joined: Sat Jun 02, 2007 12:48 pm

Post » Fri Jun 17, 2011 11:57 am

The problem could be the game's Z angle. Use 90 - [reference].GetAngle Z when doing calculations like that.
User avatar
Noraima Vega
 
Posts: 3467
Joined: Wed Jun 06, 2007 7:28 am

Post » Fri Jun 17, 2011 5:28 am

Thanks, I've only done calculations with x/y, it totally put me off xD
User avatar
Nikki Hype
 
Posts: 3429
Joined: Mon Jan 01, 2007 12:38 pm


Return to Fallout: New Vegas