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 / Move object with mouse (3d)

Author
Message
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 17th Feb 2018 09:52
Hi
I know how to move an object in x/z plane, but i dont know how to move an object (x, y, z) with the mouse.
I would like the object stuck to the mouse position on the screen.
Do you have an idea how i can do that ?

Thanks.
AGK2 tier1 - http://www.dracaena-studio.com
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 17th Feb 2018 16:19
Basically you raycast to check if the user has clicked on the object you want to move then you raycast to a point on the ground and move it appropriately

I can do a quick example if necessary
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 17th Feb 2018 16:22 Edited at: 17th Feb 2018 19:00
There you go ....its all about raycasts and finding where the screen collides with the ground or some other plane



EDITED to include Y movement from mouse wheel
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 17th Feb 2018 17:23
Hi

Thank you for your example. But what I would like is move the object in x, z AND Y .
In this example (it's like mine), I can't change the Y of the box.

So how can do that ?
Change X, Y? and Z with mouse. Set the object at the mouse position.

Another matter is : if you change the box size from 10,10,10 to 1,1,1 and click to select it, the box move but not at the mouse coordinates .
AGK2 tier1 - http://www.dracaena-studio.com
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 17th Feb 2018 17:43
Quote: "Another matter is : if you change the box size from 10,10,10 to 1,1,1 and click to select it, the box move but not at the mouse coordinates ."


Probably because the code doesn't transform the Pointerx and Pointery to actual world coordinates?

Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 17th Feb 2018 17:50
You only have X and Y mouse positions but you want to set X,Y AND Z and dont have enough inputs.... For any given position on the screen there are an infinate number of positions the obect can be at to be under the cursor. The real question is how do YOU want it to move?

If you want to move vertically then rotate the plane... you can have it in the X/Y plane and move it along that for vertical movement. You could only move the object vertically when the shift key is pressed so the user has height control separately.


You can get the original position and compare against that so that not matter what size the box is it always starts at the cursor.
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 17th Feb 2018 17:53 Edited at: 17th Feb 2018 19:01
Quote: "Probably because the code doesn't transform the Pointerx and Pointery to actual world coordinates?"


No its not that , its because the starting position of the raycast isnt stored in the StX#,Y#,Z# variables... The collision point is with the plane not the box. I was in a rush and just wanted to show the basic principle of 3D movement

I've edited the original code to allow Y movement using the mousewheel but x and z is moved with the pointer as before.

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 17th Feb 2018 22:13
@Blendman

use this example, use end_x#, end_y#, end_z# for your object position, job done!

https://www.appgamekit.com/documentation/Reference/3D/Get3DVectorXFromScreen.htm
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 18th Feb 2018 08:49 Edited at: 18th Feb 2018 08:50
Hi

Thank you very much for your answer.

@Bengismo, thanks for your example, i have modified it to get what I need .

@PartTimeCoder : Thanks a lot ! that was what I need.

Here is the code To move an object in X/Y/Z with the mouse :

AGK2 tier1 - http://www.dracaena-studio.com

Login to post a reply

Server time is: 2024-11-23 01:19:12
Your offset time is: 2024-11-23 01:19:12