Trouble with Vectors

Freeform discussion about anything related to modding Transcendence.
Post Reply
Alex_
Anarchist
Anarchist
Posts: 14
Joined: Wed Dec 23, 2009 7:26 pm

I've been having some trouble with vectors in a little mod I've been experimenting with. I can't work out a seemingly simple problem, so I think I need to ask some stuff about the basics of positions and vectors and things.

I think I understand that most vectors are simply positions, (presumably coordinates? The star the origin?) and there are also velVectors, which are velocities with a speed and direction.
Also, am I right in saying that in most cases you can use a SpaceObject in place of a position vector?

If position vectors are simply positions, then what are the functions for adding vectors and subtracting vectors for? Are they only for dealing with velVectors? I can't see a particular use for adding two sets of coordinates together, unless position vectors can be relative, not absolute from the origin of the system.

The code I have an issue with is a bit of gravity. All is well and good when I get the planets and ships to orbit the sun, but I can't seem to get the distance between gSource and the nearest "planet". The planet is a ship with a certain tag. Without the distance between the two objects, I can't get anything to work.

These are the lines of code that cannot be made to work:

Code: Select all

				(block (strength TickSkip ThePlanet)
				(setq TickSkip (ObjGetData gsource "Tickskip"))
				(setq ThePlanet (sysfindobject gsource "NB:Planet"))
				(setq strength (divide (multiply TickSkip 10000) (power (objgetdistance ThePlanet gSource) 2)))

				(if (eq strength 0)
						(ObjIncData gSource "TickSkip" 1)
						(block nil
							(ObjSetData gSource "TickSkip" 1)
							(ObjincVel gsource (sysVectorPolarVelocity (add (sysVectorAngle (objGetPos gSource)) 180) strength))						
							)
					)
				)
This is the code for orbiting the sun that works fairly well:

Code: Select all

				(block (strength TickSkip TheStar)
				(setq TickSkip (ObjGetData gsource "Tickskip"))
				(setq strength (divide (multiply TickSkip 10000) (power (sysVectorDistance gSource) 2)))

				(if (eq strength 0)
						(ObjIncData gSource "TickSkip" 1)
						(block nil
							(ObjSetData gSource "TickSkip" 1)
							(ObjincVel gsource (sysVectorPolarVelocity (add (sysVectorAngle (objGetPos gSource)) 180) strength))						
							)
					)
				)
I am aware that the not-working code will be pulling the ship in the wrong direction, but the effect is not even stronger when you get closer to planets, and the problem lies in me not being able to get the distance between the two spaceobjects.

TL:DR
Can't make code for finding distance between two space objects, one of which is gsource and the other the nearest with a certain attribute.
Help me understand vectors please :)
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

This is where i went when I was working with vectors. It is a pretty short read, but it may take some studying

http://chortle.ccsu.edu/vectorlessons/vectorIndex.html

As for the distance, are you certain that your sysFindObject is returning what you need? You should always try and dbgLog these things... so, place a (dbgLog ThePlanet) after you did the sysFindObject. Then you will see why you can not get the distance. I assume it is because the sysFindObject does not find anything. That is probably because it needs to know what kind of object to look for. I would try with this criteria string "tN +planet"
Alex_
Anarchist
Anarchist
Posts: 14
Joined: Wed Dec 23, 2009 7:26 pm

sN +Planet seems to work so far.
Thankyou :)
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Super.

For a list of Object Criteria see the wiki: http://wiki.neurohack.com/transcendence ... t_criteria
Post Reply