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 DBPro Corner / Mouse Follow With Stepping

Author
Message
Rims Flames
10
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 5th Apr 2014 12:44
Hey community i have a little dilema...I don't really know how can i make an object follow my mouse but not smooth, but like in the segment editor in FPS Creator Classic...how can i achieve this?

Thank You for help!

Rims Flames
Derek Darkly
12
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 8th Apr 2014 22:37
I'm not familiar with FPS Creator Classic

So you want the object to follow the mouse, but in set increments? Like to where the object is jumping a certain amount of space with each movement?

666GO†O666
Rims Flames
10
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 9th Apr 2014 12:17
Hey Derek Darkly!

Exactly!

Rims Flames
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th Apr 2014 16:11
It sounds like you need to create a threshold. Create variables for the last set position of the mouse. When the actual mouse coordinates have moved a specific number of units from the set position, move the object and update the set position.

Derek Darkly
12
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 9th Apr 2014 18:55
Are you wanting the movement to be along all 3 axes, or just 2 at a time like X and Y, for example?

You might want to play with PICK SCREEN
This command will calculate a relative 3D coordinate from a 2D screen coordinate.

If i get a better idea of what you want, I may try to code some kind of example if I'm able.

666GO†O666
Rims Flames
10
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 10th Apr 2014 14:09
This is the code that i have



But how can i manage to eliminate the smooth follow and add that function like in fpsc. The fact is that i don't know how to adapt this code to what i want...Really appreciate for help! Thank You again!

Rims Flames
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 10th Apr 2014 14:24 Edited at: 10th Apr 2014 14:24
Maybe something like this, where "20" is just a distance I have picked to demonstrate. Your variables will need to maintain their values between cycles. Untested but the theory should be OK:



Rims Flames
10
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 10th Apr 2014 16:16
Hey BatVink it works as it should only that has a big glitch, the object positions itself up or down but not where the mouse is.

Thank You again!

Rims Flames
Rims Flames
10
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 10th Apr 2014 17:59
I don't think that the message from a few minutes was sent but i am resending this again anyways:

The code works perfectly except that i am dragging the mouse left or right sometimes the object that i move it goes up or down.

Thank You!

Rims Flames
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th Apr 2014 23:49
There is a typo in one of the lines I wrote.

if abs(new_xp# - old_xp#) > 20 then old_xp# = new_xp#
if abs(new_zp# - old_zp#) > 20 then old_zp# = new_xp#


should be

if abs(new_xp# - old_xp#) > 20 then old_xp# = new_xp#
if abs(new_zp# - old_zp#) > 20 then old_zp# = new_zp#


Rims Flames
10
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 12th Apr 2014 00:43
Oh God i can't believe i didn't saw the misstype...but now thankfully it works thanks to you! Thank You and thanks to all for support!

Rims Flames
Rims Flames
10
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 22nd Apr 2014 21:49
Hey BatVink,

Do you know why when i moving the cursor very fast with the objects attached to it, the position gets imperfect? Like if i want to make a big wall, i am moving a bit fast up and down with the mouse sometimes and if i want to go near the last wall to make another wall, the same precision is broken, like i expect to be almost glued to the wall next to it.

Thank You!

Rims Flames
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Apr 2014 23:02
Using 20 units as the example again...

The code looks for "greater than" 20. So if you move 25 units, it will place your object at the last position + 25.

You need logic that says "if greater than or equal to 20, move it 20"

You'll need to expand the previous example because it ignores direction. If you want to move a specific number of units you'll need to take into account negative/positive too.

Also, although you are moving the object a specific number of units you still need to remember the mouse position not the object position when you move it and reset the variables. I don't have an editor here to write the code at the moment but it would be something like:



Rims Flames
10
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 23rd Apr 2014 18:48
Hey BatVink,

Thank you for the fast reply!

The code doesn't really work i mean the object now doesn't appear on the screen or if it does, it goes from up to down very fast and then disappears.

Thank You again!

Here is the code for an editor prototype that i am testing the codes.



Rims Flames
Rims Flames
10
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 27th Apr 2014 21:40
Anyone can help me with code that BatVink wrote please?

Thanks in advance!

Rims Flames
nonZero
12
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 12th May 2014 21:23
Unfortunately, your approach is wrong from what I can see of your code (I'm viewing it on a phone). You need to use rounding based on where the mouse /is/, not how much it moved. That maintains a constant. Here's a 2D example:

How about you take the distance you want for each step as /s/
Now your coordinates are:
x = (x / s) * s
y = (y / s) * s
Basically dividing by s gives you a value which (since these are ints) gets rounded-off to the nearest whole number (if you're working in floats, then you need to write a quick rounding function). That gets then multiplied by s, resulting in the nearest step.
Example:
x = 109
s = 20
x / s = 109 / 20 = 5.45
5.45 rounds to 5
5 * s = 5 * 20 = 100
Now 100 is the nearest 20unit step from 109.

"Oh nonZero, let me tell you, I love you." -- Dark Java Dude 64, Vice-Kapitan of nASA(nonZero's Awesomeness-Spreading Association)
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 23rd May 2014 13:17 Edited at: 23rd May 2014 13:18
What nonZero said - use absolute placement. BatVink's example uses relative placement, meaning the error will increase over time.



Your mod has been erased by a signature

Login to post a reply

Server time is: 2024-04-19 14:17:59
Your offset time is: 2024-04-19 14:17:59