Aiming a rocket

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Rademanc
Posts: 16
Joined: Sat Apr 25, 2009 4:21 pm

Aiming a rocket

Post by Rademanc »

How do I am a rocket at something?
I have a force that I am applying to the end of the rocket, but how do I aim it at a particular entity?
Impulses?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Aiming a rocket

Post by Norbo »

There are a variety of approaches you can take depending on what kind of behavior you want to achieve.

Having a force pushing the object forward while impulses/other forces are applied elsewhere on the rocket to maintain its heading would work. One fairly simple method for keeping an object headed in approximately the right direction is to cross the forward vector of the rocket with the normalized direction vector pointing from the rocket to the target object. The sine of the magnitude of the cross product provides the angle difference, while the normalized cross product vector provides the axis with which the angle is associated.

You can apply a torque based on the cross product result to change the angular motion. One possibility would be to use torque = axis * angle * factor, where factor is some scaling factor that basically defines how strong the angular 'spring' is. To apply the torque, you can use an entity's applyAngularImpulse method. This method with no further modifications will likely end up with your rocket 'snaking' towards the target, since the spring will continually overcompensate.

Depending on what sort of behavior you want, you may end up working directly with velocities instead of forces applied at certain locations. It can be easier to get precise behavior with directly set velocities. For example, instead of using what amounts to a spring in the above example, you could directly set the angular velocity of the missile each frame based on the heading error. As the error reduced, you could reduce and eliminate the angular velocity preventing it from overcompensating and 'snaking.'
coimbra79
Posts: 33
Joined: Thu Dec 29, 2011 12:42 am

Re: Aiming a rocket

Post by coimbra79 »

ooo!!
I need to understand this topic ... In fact I have a similar problem too:
I made a A.I.
This can drive a vehicle (hovercraft) complex autonomously along a track (using raycast)... Unfortunately I can not to guide the oject in direction of movement. I am correcting my code, based on what you said about ...

Code: Select all

Vector3 tmpVec;
                        tmpVec= Vector3.Cross(Main1.space.Entities[mIA.objRef].WorldTransform.Forward, Vector3.Normalize(Main1.space.Entities[mIA.objRef].LinearVelocity));
                        double Angle= Math.Sin(Convert.ToDouble(tmpVec.Length()));
                        tmpVec.X = 0;
                        tmpVec.Y = Convert.ToSingle (Angolo)*-50;//the overcraft speen only in Y axis
                        tmpVec.Z = 0;
                        Main1.space.Entities[mIA.objRef].ApplyAngularImpulse(ref tmpVecIma);
??what wrong??
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Aiming a rocket

Post by Norbo »

The angle should be the arcsine of the cross product length, not the sine. Additionally, since the impulse only operates around the Y axis, it would probably be good to only measure the angle around the Y axis. The rest depends on the exact behavior you want.
coimbra79
Posts: 33
Joined: Thu Dec 29, 2011 12:42 am

Re: Aiming a rocket

Post by coimbra79 »

TANKS NORBO!

unfortunately does not seem to work, but I do not think that is due to the formula.
I tried to apply a pulse persistent to object on the y axis, this rotates up to about 180 ° and then slowly stops ...
what is wrong?
Keep in mind that the AI ​​apply at the same object more forces to correct the trajectory along the track at same frame ...
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Aiming a rocket

Post by Norbo »

Unfortunately, there's not enough information for me to know exactly what's wrong. I would recommend drawing out every step of the process to visualize the concept and ensure that it is correct. Once you have a set of expectations for how it works, create a test situation and put some break points in. Then, look at the values in sequence and compare them against your expectations.
coimbra79
Posts: 33
Joined: Thu Dec 29, 2011 12:42 am

Re: Aiming a rocket

Post by coimbra79 »

I understand where you hide the error ... I can not apply physical forces and simultaneously manage the transformation matrix of an entity in writing, in fact, applying owar rule to an other entity that not followed by the camera, everything works properly...
my mistake is that to orient a obj followed by camera, apply an abrupt transformation to the matrix of obj making it identical to that of the camera, after apply forces to the obj I imagine that the error is dependent on this.
now I'm trying to apply the same rules that uses AI to orient a obj when I move the camera ...
unfortunately in my simulation, to simulate the movement of the main obj (controlled by the player) move the camera while the obj and then orient the obj with the sad technique that I said

CONCLUSION:
MATRIX TRANSFORMATION + APPLYANGULARIMPULSE (OR INCREMENT OF Angular Momentum) DOES NOT WORK.
SOLUTION
ORIENT OBJ by using THE PHYSICAL FORCES IF YOU MUST ASSIGN TO THE SAME OBJ other FORCEs IN A SECOND TIME
Post Reply