Mosue Aim Turret?

Hi there,

Me and my friend are having a small competition, we have to build some sort of fighting vehicle.

Now im planning on building a tank, and i want the main turret to point at where my mouse is. Ive tried using and eye pod and wiring a vector thruster straight to an adv pod controller, but iv’e had no luck.

So facepunch, would you be so kind as to help me out?

I use this solution and i think it works quite well.


@name RedReaper's Mouse Aim Expression
@inputs [Turret]:entity On
@outputs 
@persist Mul Owner:entity TurAng:angle
@trigger 
interval(50)
if(first())
    {Owner = entity():owner() #You
     Mul = 6}#Multiplier
    
if(On == 1)
    {   TurAng = (Owner:eyeAngles() - Turret:angles()):setRoll(0)
        Turret:applyAngForce((TurAng + ($TurAng*4)) * (Turret:mass() * -Mul))
    }


The chip applies force based on the prop’s owner’s eye angles (direction you’re looking). Entity marker to a big phx cube (I think this one is set up for 0.5), use it to find the forward on the cube (or stacker shadows) before you build the turret around it. Multiplier is based on prop physical size, not weight.

if you want a stabilized gun, your seat should be ballsocket-centered to the vehicle, then adv ballsocket the seat to the world with -0.01/0.01, friction 5 on all settings. Look throuhg the last 30 pages of “post your current wip” to find a lot of stuff about tank building. :science:

[editline]21st February 2011[/editline]

you can find mouseaim codes on the E2 and wire wikis, please look there next time before asking FP

thanks for the help island sorry, FP is like my first place to go when in stuck :s


@name Base Oriented Pointer (applyForce)
@inputs [Base Prop]:entity Dir:vector
@outputs 
@persist 
@trigger 

runOnTick(1)

#Dir = owner():eye() #uncomment this if you're lazy

QBase = quat(Dir, Base:up())
QProp = quat(Prop)

Q = QBase/QProp
Torque = Prop:toLocal(rotationVector(Q) + Prop:pos())

Prop:applyTorque((Torque*1500 - Prop:angVelVector()*40)*Prop:inertia())

Turret things like a pro

Theres a couple ways to do it. In my experience, applyTorque, like reaper used, is the most stable

No way, wire wheels and weld-latches is where it’s at!

[editline]21st February 2011[/editline]

no really, applyangforce or applytorque is pretty universally used now…a few people use offsetforce or propcore (nice use for propcore), but it’s pretty universal.

Cool kids use numpad winches.
Pros use motor tool and hoverballs.

I used to be a cool kid :frown:

I still use basic wire…does that make me…forever alone?

yes.

and motor tool is fail. gotta engine power it.

Best aiming system evar:

[editline]derp[/editline]
Only ZeosPantera could make an aiming system engine powered with gears. Only zeos.

Thats one of the coolest things I’ve ever seen

Lulz, I remember this fossil. Good times.

Sorry for the bump…

is there a way to limit the angles of this thing? also add a way that it stops to face forward when you exit the seat it’s connected to?

Yeah, something like


Dir = (Seat:driver() ? Seat:driver():eye() : Base:forward())

would work. What it does is checks if the seat’s driver exists. If so, then the direction is the one that the driver is looking in, otherwise it locks the gun to point in the forward position of its base. I use this update in most of my weapon systems.

[editline]3rd March 2011[/editline]

You can use this to figure out which direction the base prop considers to be forward. It’s served me well since I tore my hair out making it. I hate holos.


@name Entity Origin Pointer

if (dupefinished())
{
    reset()
}

if (first())
{
    E  = entity():isWeldedTo()
    Or = E:pos()
    
        #X axis
    holoCreate(2524)
    holoScale(2524, vec(4,0.05,0.05))
    holoShadow(2524, 0)
    holoColor(2524, vec(255,0,0), 255)
    holoPos(2524, Or + E:forward()*24)
    holoAng(2524, E:forward():toAngle())
    holoMaterial(2524,"models/wireframe")
    holoParent(2524,E)
    
    
        #Y axis
    holoCreate(2525)
    holoScale(2525, vec(4,0.05,0.05))
    holoShadow(2525, 0)
    holoColor(2525, vec(0,255,0), 255)
    holoPos(2525, Or + (-E:right())*24)
    holoAng(2525, (-E:right()):toAngle())
    holoMaterial(2525,"models/wireframe")
    holoParent(2525,E)
    
    
        #Z axis
    holoCreate(2526)
    holoScale(2526, vec(4,0.05,0.05))
    holoShadow(2526, 0)
    holoColor(2526, vec(0,0,255), 255)
    holoPos(2526, Or + E:up()*24)
    holoAng(2526, E:up():toAngle())
    holoMaterial(2526,"models/wireframe")
    holoParent(2526,E)  
      
}

[editline]3rd March 2011[/editline]

As for limiting the angles of it, try clamping the direction vector local to the base. If you want any help from me with that you’d have to wait for me to discover that for myself, as I’ve never really needed it.

Awesome!, now it works like a charm…

I guess this is asking for a little bit more, but could someone do a tutorial on how exactly to apply these scripts? I’ve looked around at E2 tutorials and then attempting to implement these but I’m just not getting anything.

Maybe a bit of instruction? There’s nowhere to find anything on turrets and whatnot, and I don’t know if I want to learn all of E2 just to play on GGG and build a few tanks.

You need to setup an entity marker then wire it to the e2, failing that there are no shortcuts but learning e2 is worth it.

How does that work if I want my gun’s traverse to be different from my turrets? I want my turret to rotate horizontally and my gun to rotate vertically.

Axis the turret to the base prop. The turret’s horizontal force component will be imparted entirely on the base, giving the illusion that you’re not just totally cheating :v:

[editline]22nd March 2011[/editline]

This is pretty much what my chip is designed for, if you’re using that one.