+ Reply to Thread
Results 1 to 8 of 8

Thread: [E2 Help] Entity -> Direction Vector

  1. #1
    Inactive Alchemise is on a distinguished road Alchemise's Avatar
    Join Date
    Oct 2008
    Posts
    18

    Default [E2 Help] Entity -> Direction Vector

    Hi

    Just making a simple follower drone at the moment, it hovers just above a player; aims a turret etc. I'm trying to make as much of my contraption built onto the one chip as possible.

    I have the vertical stablization and direction thrusters sorted, using the applyForce(V) function; but I haven't managed to implement the rotational stablization.

    I had in mind to use the applyOffsetForce(V, V) function twice, to replace two thrusters which are a set distance from the centre, and are angled perpendicular to the device so as to develop torque.

    Two problems with this. Firstly, the direction vector for the force. I can't work out how to acquire the direction vector of an entity. Its something to do with E:toWorld(V), but I'm not sure. Once I have the direction of the entity (the chip itself), I can then simply rotate it 90 degrees in the yaw axis. That way it will always point perpendicular to the entity.

    Second problem is the position vector. I need to find the coords of a point just in front of and behind the chip; that changes relatively. This could be done by welding a gps to where I need the coords, but this defies the whole single chip ethos. The only way I can think of doing it is with an entity marker and little prop welded on to the device, or a gps.



    Any help would be greatly appreciated.

    Oh, and by the way - is it possible to capture chat text as a string? I'm thinking typing a target's name into chat and it running off to kill it.

  2. #2
    Master of Mars


    Magos Mechanicus will become famous soon enough Magos Mechanicus will become famous soon enough Magos Mechanicus's Avatar
    Join Date
    May 2008
    Posts
    834

    Default Re: [E2 Help] Entity -> Direction Vector

    You know, entities don't have one direction vector but rather 3 of them. They are forward, right and up, and the corresponding E2 functions are E:forward()/right()/up(). They return unit vectors in the world coordinate system that point in the appropriate direction at the time the function is run. For instance, the points you have marked out might be something like this:
    Code:
    E:pos()+10*E:forward() and E:pos()-10*E:forward()
    
    .
    toWorld() is indeed quite useful as a shorthand for stuff you want to define locally, though. The way it works is that
    Code:
    E:toWorld(vec(X,Y,Z)) = E:pos() + X*E:forward() + Y*E:right() + Z*E:up()
    
    Combining those two, for that rotation there you could for instance do
    Code:
    V=vec(10,0,0) Force=100*Ent:right()*Ent:mass()
    Ent:applyOffsetForce(Ent:toWorld(V),Force)
    Ent:applyOffsetForce(Ent:toWorld(-V),-Force)
    
    The 10 in V and the 100 in Force are fiddlable constants that can be useful for adjusting to stuff that's very large or whatever - multiplying the force by the mass of the entity helps make its effects consistent.
    I can wire anything directly into anything! I'm the Professor!
    -Professor Hubert Farnsworth

  3. #3
    Inactive Alchemise is on a distinguished road Alchemise's Avatar
    Join Date
    Oct 2008
    Posts
    18

    Default Re: [E2 Help] Entity -> Direction Vector

    Thanks for those lines, they get me the vectors I wanted. Makes perfect sense, shame I didn't think of it. [Pos] + k*[Dir]

    Although, at the moment I see to be having an entity problem.

    My design is a phx disk, with a small arm connected to hyrdualics to be the turret mount. I was using the entity marker jobby on the arm itself so I could get the elevation to the target.

    Whenever I dupe my design, the entity marker dies and the program gets stuck trying to do operations on a null entity. It locks up the chip, and I can't wire anything to it. Sometimes rewiring works, but most of the time it doesn't.

    Is there any other way of getting entity info from a prop? Or is there a way of solving the lockup issues?

    Last edited by Alchemise; 02-13-2009 at 05:29 PM. Reason: added pic

  4. #4
    Inactive Alchemise is on a distinguished road Alchemise's Avatar
    Join Date
    Oct 2008
    Posts
    18

    Default Re: [E2 Help] Entity -> Direction Vector

    Okay, its a new bug. The old code still works fine when rewired. I can wire the old one, and update the chip with the new code and still get this error message:

    Timer Error: entites\gmod_wire_expression2\core\entity.lua.352: attempt to index global 'entity' (a nil value)
    Anyone got any idea what the error means, or what it is caused by?

    I've included my code if you think you can work it out from there. Arm is the entity marker input, Flip and Fire are user inputs to toggle the drone and its weapons. Scan is linked to the Flip input, and just scans for the target (me)

    Code:
    @name follower
    @inputs Scan Flip Fire Arm:entity
    @outputs Guns Hyd
    @persist ForVec:vector ThrPosF:vector Arm:entity ThrPosB:vector ThrDir:vector Tr X DZ F D DX DY QX QY ArmPi AngArm:angle Pos:vector TPos:vector DThrust:vector Self:entity Target:entity
    interval(10)
    ############################
    #Follower Drone by Alchemise
    ############################
    ############################
    #Vertical Stabilzation
    ############################
    
    Self = entity()
    Pos = Self:pos()
    QZ = TPos:z()
    DZ = Pos:z()
    T = 30*(420 - Pos:z()) - 50*$DZ
    
    ############################
    #Target Finding
    ############################
    
    if(Scan == 1){
    findInSphere(Pos, 100000)
    findClipToName("Alchemise")
    Target = find()
    }
    
    ############################
    #Movement
    ############################
    
    TPos = Target:pos()
    D = Pos:distance(TPos)
    DX = TPos:x() - Pos:x()
    DY = TPos:y() - Pos:y()
    QX = Pos:x()
    QY = Pos:y()
    QZ = Pos:z()
    if(D < 500){
    DThrust = vec(-200*$QX*Flip, -200*$QY*Flip, T*Flip)}
    else{
    DThrust = vec(Flip*DX, Flip*DY, Flip*T)}
    applyForce(DThrust)
    
    ############################
    #Rotation & Arm Pitch
    ############################
    
    AngArm = Arm:angles()
    ArmPi = Arm:elevation(TPos)
    if(ArmPi > 0){Hyd += 0.4}
    if(ArmPi < 0){Hyd -= 0.4}
    Hyd = clamp(Hyd, 2, 55)
    if(Flip == 0){Hyd = 2}
    else{Hyd = Hyd}
    X = Self:bearing(TPos)
    Tr = ((0.5*X + 2*$X)*-0.3*Flip)
    if((abs(ArmPi) < 5) & (abs(X) < 5) & (Fire == 1)){
    Guns = 1}
    else{Guns = 0}
    ForVec = Self:forward()
    ThrPosF = Pos + 2*ForVec
    ThrPosB = Pos - 2*ForVec
    ThrDir = Self:right()
    
    applyOffsetForce(Tr*ThrDir, ThrPosF)
    applyOffsetForce(-Tr*ThrDir, ThrPosB)
    

  5. #5
    Newbie Programmer ZeikJT will become famous soon enough ZeikJT's Avatar
    Join Date
    Dec 2008
    Location
    California
    Posts
    1,394

    Default Re: [E2 Help] Entity -> Direction Vector

    Quote Originally Posted by Alchemise View Post
    Okay, its a new bug. The old code still works fine when rewired. I can wire the old one, and update the chip with the new code and still get this error message:

    Timer Error: entites\gmod_wire_expression2\core\entity.lua.352: attempt to index global 'entity' (a nil value)

    Anyone got any idea what the error means, or what it is caused by?
    You must have an older version of the SVN. I checked line 352, it doesn't have any entity defined anywhere near there.
    If you still have problems after updating post again.
    Against stupidity the Gods themselves contend in vain.
    -Friedrich Schiller

    The flame puts me in the mood to "Do it!".
    -Dart, Legend of Dragoon

  6. #6
    Master of Mars


    Magos Mechanicus will become famous soon enough Magos Mechanicus will become famous soon enough Magos Mechanicus's Avatar
    Join Date
    May 2008
    Posts
    834

    Default Re: [E2 Help] Entity -> Direction Vector

    One alternative to the entity marker is to use the find extension. Most of the time this is for applications that always operate on the same entity, so you usually only have to run it once. My method is to first find the model name of my prop (right click in the spawn menu, there is a copy to clipboard option) and then do:
    Code:
    @persist Arm:entity
    if(!Arm){findIncludeModel("Modelname here")
    findInSphere(entity():pos(),300)
    Arm=findClosest(entity():pos())
    findDisallowModel("Modelname here")}
    
    The last line isn't usually necessary for me, but since you use the find extension for target aquisition it's probably best to make sure your whitelist is clean.
    I can wire anything directly into anything! I'm the Professor!
    -Professor Hubert Farnsworth

  7. #7
    Inactive Alchemise is on a distinguished road Alchemise's Avatar
    Join Date
    Oct 2008
    Posts
    18

    Default Re: [E2 Help] Entity -> Direction Vector

    I would have be cussing for hours trying to get it to work. Yea, my svn was out of date. Damn you all for updating it so often =)

    The newer version of entity marker is a lot more stable, and doesn't churn out errors. Before when I duped my drone all the chips flew off the top.

    It works beautifully now.

    No I jsut need to come up with some code to switch targets etc. Maybe add some other uses. I'm thinking if come up with a practical find black/white list I could get it to find certain props, maybe even use a grabber on them.

    Anyways, thanks for the help guys.

  8. #8
    Lurker |Voodoo| is on a distinguished road |Voodoo|'s Avatar
    Join Date
    Apr 2008
    Location
    Buffalo, New York
    Posts
    36

    Default Re: [E2 Help] Entity -> Direction Vector

    This look like an old dupe I have (did not make it) but since the change over to Ep2, it has not worked quite right.
    In quantum physics, the Heisenberg uncertainty principle states that the values of certain pairs of conjugate variables (position and momentum, for instance) cannot both be known with arbitrary precision. That is, the more precisely one property is known, the less precisely the other can be known.

+ Reply to Thread

Similar Threads

  1. Expression2: Direction Vector
    By RabidCrab in forum Expression 1 & 2
    Replies: 2
    Last Post: 01-23-2009, 06:50 PM
  2. Vector Thrusters and Vector Direction with a Pod
    By zentiger in forum Technical Support
    Replies: 8
    Last Post: 09-25-2008, 11:01 PM
  3. Finding direction for vector thruster
    By sukasa in forum Technical Support
    Replies: 3
    Last Post: 01-03-2008, 07:38 AM
  4. Normalizing vector direction.
    By Shockbolt in forum Technical Support
    Replies: 6
    Last Post: 11-17-2007, 03:28 AM
  5. Beacon Sensor "direction vector" suggestion
    By kuro11 in forum Ideas & Suggestions
    Replies: 10
    Last Post: 08-20-2007, 07:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots