E2 little help needed

hello if there is any one who is good at e2 applyTorque i would apreciate making that :


Cannon1:applyTorque(((AngL + $AngL * 5) - Cannon1:angles():roll()) * 2000)

VERY STABLE because now it just rolls around the angle… so does anyone want to help me ?

PS: AngL is a vec with angle in it eg. Ang = vec(Angle,0,0) not in that order

You’re probably better off asking this on the wiremod forums

Why would you use angles with applyTorque? It is meant to be used with directional vectors.



Inertia = shiftL(ang(Cannon1:inertia())) #persist this
Angle = Cannon1:toLocal( TargetAngle )*200 - Cannon1:angVel()*20
Cannon1:applyAngForce( Angle * Inertia )


i use angle because later thats usefull to determine where the cannonball will hit. checking the code thx

[editline]27th September 2013[/editline]

i did ask on the wiremod forums but noone yet responded and i know that this forum has more people

EDIT:

the code works fine, it wobbles a little bit but i cano live with that more than with my old code, thanks

[editline]27th September 2013[/editline]

EDIT2:

sorry but something looks wrong when i turn, it seems like it depends on the world angle. could you make it on applyTorque ? because i think it will be much more stable

applyTorque and applyAngforce are exactly the same, except one takes vectors and one takes angles. Stability will be the same no matter which you choose to use.

How are you aiming them? Using your aim position? At any rate, it sounds like you want the angles to be relative to your ship, rather than the world.



@inputs Ship:entity Cannon:entity

if (first())    {
    
    function entity:aimCannon( Angle:angle )    {
        local Inertia = shiftL( ang( This:inertia() ) )
        local Target = This:toLocal( Angle ) * 200 - This:angVel() * 20
        This:applyAngForce( Target * Inertia )    
    }
    
    interval(90)  
  
} elseif (clk())    {

    interval(90)
    
    TestPitch = sin( curtime() * 50 ) * 12 + 12
    TestYaw = cos( curtime() * 50) * 24

    Cannon:aimCannon( Ship:toWorld( ang( TestPitch, TestYaw, 0 ) ) )

}


This is perfectly stable, so if you experience wobble, its something faulty in your physical setup, not the code.

WOW i totally dont understand sinus and cosinus, also i have no idea why its in there. but if it works i will love you XD i also see you added yaw, that would allow me more :3

and how would i use it ? like ship would be an entity at the center of the ship. where do i put my angle ? or is it where i aim ? cuz the angle i have is just a numpad controlled number which controls the cannons

Never mind the sin/cos, its just in there to angle the cannon around to test it without wiring any inputs.

Ship is whatever you want the cannon to aim relative to, so probably the main prop.



Cannon:aimCannon( Ship:toWorld( Desired Angle Goes Here ) )