Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / 3D Character : clic and go with mouse

Author
Message
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 31st Mar 2023 09:38 Edited at: 31st Mar 2023 09:45
Hi

I'm trying to move a 3D hero with the mouse.
I use the character features for collision, it works great.

I have made this example, and it seems to work.

I would like to know if it can be improved

Thanks



Cheers
AGK2 tier1 - http://www.dracaena-studio.com
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 31st Mar 2023 20:25
Hi,
I prefer vector mathematics in this case.
I have rebuilt your example and use my vector math lib that I presented here years ago.
I also took the opportunity to update the lib.
Of course you can also use other libs that are floating around in the forum.


from Scraggle (2D)

I know there was another good Vector Math Library here in the forum, but unfortunately I didn't find it quickly.

The advantage of changing the code is that a direct path is taken to the destination. And not only horizontally vertically and diagonally.

Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 1st Apr 2023 03:04 Edited at: 1st Apr 2023 03:07
I have been given this code which works. Which i think is what MadBit posted.
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 1st Apr 2023 10:17 Edited at: 1st Apr 2023 10:33
HI

Thank you for your answers
I will try your code.

Blinkok : what is "pos", in your function ? The position of the object ?

MadBit : thanks, I will try it




I have made a little change, to get a direct path to the target too, and rotate the character in the direction of the target

AGK2 tier1 - http://www.dracaena-studio.com
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 1st Apr 2023 22:49 Edited at: 1st Apr 2023 22:50
Sorry blendo. I should have posed the type which is just x/y/z floats.
Quote: "what is "pos", in your function ? The position of the object ?"

pos is the point on the object where the raycast hits, it is passed as a ref so you can use the values outside the function (To position an object or camera for example)

You still need to normalize the vector when you cast your ray

Login to post a reply

Server time is: 2024-03-29 07:13:42
Your offset time is: 2024-03-29 07:13:42