Gamestudio Links
Zorro Links
Newest Posts
Purchase A8 full licence version
by ukgamer. 04/29/26 18:09
Z9 getting Error 058
by k_ivan. 04/25/26 19:13
ZorroGPT
by TipmyPip. 04/25/26 16:09
Stooq now requires an API key
by jcl. 04/13/26 09:42
Strange "Alien" Skull created with >Knubber<
by NeoDumont. 04/10/26 18:58
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
0 registered members (), 5,733 guests, and 39 spiders.
Key: Admin, Global Mod, Mod
Newest Members
ukgamer, valino, juergenwue, VladMak, Geir
19210 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Vector problem #216970
07/20/08 13:43
07/20/08 13:43
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Hi,

I've got the following problem:

I'm developing a point&click adventure and use paths for player movement.

When clicking left mouse button I scan for the node next to the current mouse position and set it as destination for the moving entity. So far so good ...

But I have to set many path nodes in WED so that the destination isn't that far away from the mouse position ...

In most cases the mouse position is between two nodes ... as we do not take care of the height we can see it like a triangle, right?
One side would be the connection of the two nodes and the two other sides would be the connection from the mouse position to the two nodes.
As I don't want the moving entity to leave the path itself, I'd like to move the mouse position point onto the connection line of the two nodes, so that it lies between the two nodes ... I hope you can follow me (hard to describe).



Can anybody help me how to calculate that ... I have the coordinates of the mouse position when clicked and I have the coordinates of the two nodes ... how to move the mouse position so that it lies on the line between the two nodes ???

Best regards,
Pegamode.

Re: Vector problem [Re: pegamode] #217005
07/20/08 18:18
07/20/08 18:18
Joined: May 2006
Posts: 90
England
TigerTao Offline
Junior Member
TigerTao  Offline
Junior Member

Joined: May 2006
Posts: 90
England
I think you can either do this using vec_dot though I would use a simpler and more accurate method of using vec_lerp.

Re: Vector problem [Re: TigerTao] #217006
07/20/08 18:21
07/20/08 18:21
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Could you explain how I would do this using vec_lerp or vec_dot?

Maybe with a little code example?

Would be great. Thanks.

Best regards,
Pegamode

Re: Vector problem [Re: pegamode] #217021
07/20/08 20:31
07/20/08 20:31
Joined: May 2006
Posts: 90
England
TigerTao Offline
Junior Member
TigerTao  Offline
Junior Member

Joined: May 2006
Posts: 90
England
ok using vec_lerp:

Im just going to assume that you can tell which nodes the mouse was clicked between and the location where the mouse was clicked at . We will call these as vectors Node_A, Node_B and Mouse_Pos.

var mouse_dist;
node_distance;
line_pos[3];
new_mouse_pos[3];

mouse_dist = vec_dist(Node_A.x,Mouse_Pos.x);
//find the distance of the mouse position from the current node.

node_distance = vec_dist(Node_A.x,Node_B.x);
//also find the distance from that node to the other node.

line_pos = (1/node_distance) * mouse_dist;
//get the value of how far between the two nodes we place the new mouse position

vec_lerp(new_mouse_pos,Node_A.x,Node_B.x,line_pos);
//find the vector of where the new mouse position is

Mouse_Pos = new_mouse_pos;
//set your mouse location to the new mouse position

edit: This wont work if you click too far from the nodes so the distance from node to mouse is larger than the distance from node to node. Its one way of doing it though.

Last edited by TigerTao; 07/20/08 20:54.
Re: Vector problem [Re: TigerTao] #217087
07/21/08 09:57
07/21/08 09:57
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Thanks TigerTao ... I'll try that.

Best regards,
Pegamode.


Moderated by  HeelX, Spirit 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1