# Hitting an object and then moving in its angular direction

Please take a moment to consider if this thread is worth bumping.

## Recommended Posts

I think is the right title for this.

I have attached a helpful sketch to show what I mean.

I want to have the red object, in a direction, doesn't have to be forward can be from any direction.

Upon hitting the green object it then travels along the wall in the same direction as the object is angled at an equal distance from the wall.

Hitting the wall and getting the objects position and rotation is easy enough, but, what do I need to look at to start working on the movement aspect of it?. It is going to have to offset the position of the red object as it moves, I know that much. But, what functions and possibly math would I need to be looking at to achieve this?

##### Share on other sites

Are we talking about physical or nonphysical movement?

If it's just nonphysical movement and you want to move in the direction of the green object, it's pretty simple.

1. Get the target's rotation. (target_rot)
2. Figure out how much you want to move. (step_distance)
3. Create a vector whose X (forward) length is your step_distance.
4. Rotate that vector by target_rot, so it will match its direction.
5. Move from llGetPos() to that offset.

Or in code:

```key target = "d65f8e9b-6ede-41ec-f8f4-d57e3aba901f";
rotation target_rot = llList2Rot(llGetObjectDetails(target, (list)OBJECT_ROT), 0);

float step_distance = 0.1;
vector offset = <step_distance,0,0> * target_rot;
llSetPos(llGetPos() + offset);```

##### Share on other sites

33 minutes ago, Wulfie Reanimator said:

Are we talking about physical or nonphysical movement?

If it's just nonphysical movement and you want to move in the direction of the green object, it's pretty simple.

1. Get the target's rotation. (target_rot)
2. Figure out how much you want to move. (step_distance)
3. Create a vector whose X (forward) length is your step_distance.
4. Rotate that vector by target_rot, so it will match its direction.
5. Move from llGetPos() to that offset.

Or in code:

```
key target = "d65f8e9b-6ede-41ec-f8f4-d57e3aba901f";
rotation target_rot = llList2Rot(llGetObjectDetails(target, (list)OBJECT_ROT), 0);

float step_distance = 0.1;
vector offset = <step_distance,0,0> * target_rot;
llSetPos(llGetPos() + offset);```

Would it be the same if the object was physical, or is that a whole other kettle of fish entirely?

##### Share on other sites

Would it be the same if the object was physical, or is that a whole other kettle of fish entirely?

a way is to calculate as Wulfie shows to get the destination, then use llMoveToTarget to move to it

##### Share on other sites

Would it be the same if the object was physical, or is that a whole other kettle of fish entirely?

The only real difference for physical movement is that instead of using step_distance as an offset to move into with llSetPos (or similar), you'd use step_distance as the new force/velocity vector. step_distance would essentially become force_strength, which you'd give to llSetVelocity (or similar).

But if the target is physical as well, its rotation may not be the direction it's moving in.

What are you trying to do exactly? What's the context?

Edited by Wulfie Reanimator
##### Share on other sites

2 hours ago, Wulfie Reanimator said:

The only real difference for physical movement is that instead of using step_distance as an offset to move into with llSetPos (or similar), you'd use step_distance as the new force/velocity vector. step_distance would essentially become force_strength, which you'd give to llSetVelocity (or similar).

But if the target is physical as well, its rotation may not be the direction it's moving in.

What are you trying to do exactly? What's the context?

Improving my wall Walker. I have moving up and down, entering and exiting the wall walk extremely fluid but moving left and right has been a constant issue as you never ever hit the wall straight on. So going left or right you end up moving away from the wall, so I need to keep my distance to the wall but move left and right relative to its position and angle.

I am shamefully weak when it comes to rotations. I know basic rotation but when it comes to involving more advanced stuff I am unsure what to do. And I am unsure exactly what subjects to study to get a better understanding of rotation and movement.

##### Share on other sites

I am shamefully weak when it comes to rotations. I know basic rotation but when it comes to involving more advanced stuff I am unsure what to do. And I am unsure exactly what subjects to study to get a better understanding of rotation and movement.

I am too, I'm not sure what to point you towards as most of my knowledge comes from intuition after having observed vectors for years in SL. I'm very math-dumb and barely know any proper vector math, let alone trigonometry, or quaternions specifically.

For me, it mostly boils down to:

X = forward, Z = up.

vector * rotation = the vector now exists in that coordinate space. If the vector was pointing forward, it still does, even if the numbers are different.

vector / rotation = the vector has been removed from that coordinate space. If the vector was pointing forward, Y and Z will be zero.

rotation * rotation = combines them clockwise.

rotation / rotation = combines them counter-clockwise.

Those assumptions get me where I need to be, 95% of the time.

Edited by Wulfie Reanimator
##### Share on other sites

Improving my wall Walker. I have moving up and down, entering and exiting the wall walk extremely fluid but moving left and right has been a constant issue as you never ever hit the wall straight on. So going left or right you end up moving away from the wall, so I need to keep my distance to the wall but move left and right relative to its position and angle.

look into using llCastRay to find the surface that you are traversing, then use llMoveToTarget or llSetForce to move slightly in the direction of travel to a point just below the surface [ adjusted for the width of agent size ]

when the surface is non-phantom then we get resistance. The non-phantom surface will try to push us out and our  movement method will try to push us in to the surface. When we get the balance of this right then we get a sticky magnet effect, and we can walk around surfaces like cylinders, outside corners, etc

Edited by Mollymews
[ ]