Page 1 of 1

Prevent a sprite (which follows the mouse) out of a circle?

Posted: Wed Oct 14, 2015 12:04 pm
by sinisrus
Hello,

How to prevent a sprite (which follows the mouse) out of a circle?
I want a circular area bounded to a sprite

Re: Prevent a sprite (which follows the mouse) out of a circ

Posted: Wed Oct 14, 2015 1:50 pm
by Juan Carlos
You have searched in the Hollywood examples

Re: Prevent a sprite (which follows the mouse) out of a circ

Posted: Wed Oct 14, 2015 5:05 pm
by sinisrus
Hello,

Yes I searched but did not find

do you have any idea?

Re: Prevent a sprite (which follows the mouse) out of a circ

Posted: Wed Oct 14, 2015 8:12 pm
by Juan Carlos
No because I know the problem because I though made a sniper game with the mouse pointer and the gun point of view but web have no so good examples and I think that in this forum we are ten members with problems to make routines and convert from other language is imposible Hollywood has diferent sintaxis of java or C

Re: Prevent a sprite (which follows the mouse) out of a circ

Posted: Thu Oct 15, 2015 4:34 pm
by TheMartian
Hi

Just a thought... May be you can sort of reverse the problem and create a bigger circular sprite as a sort of zone. If they collide - you are inside the zone and all is well. I guess it should work though I haven't tried. It has the advantage that the 'zone' sprite can be moved around easily if that is required

regards
Jesper

Re: Prevent a sprite (which follows the mouse) out of a circ

Posted: Thu Oct 15, 2015 5:32 pm
by sinisrus
@themartian

yes it works but it is not perfect

I would like to know how to have an object that rotates around a fixed axis which follow the mouse

Re: Prevent a sprite (which follows the mouse) out of a circ

Posted: Thu Oct 15, 2015 8:10 pm
by jalih
sinisrus wrote:@themartian
I would like to know how to have an object that rotates around a fixed axis which follow the mouse
Not sure, if I understood right...

If you need to calculate the angle in a circle (useful, if you want to rotate object towards mouse pointer):

Code: Select all

x1, y1 ; Center point of the circle
x2, y2 ; Mouse pointer coords

; Calculate angle in radians. Remember to convert to degrees, if needed. 
angle  = Atan2(y2 - y1, x2 - x1)
If you need to calculate point in a circle:

Code: Select all

angle  ; angle in radians
r      ; radius

x1, y1 ; Center point of a circle
x1, y2 ; Point in a circle

; Calculate point in a circle
x2 = x1 + Cos(angle) * r
y2 = y1 - Sin(angle) * r

Re: Prevent a sprite (which follows the mouse) out of a circ

Posted: Fri Oct 16, 2015 1:05 pm
by sinisrus
@Jalih

Thank you :-)

Re: Prevent a sprite (which follows the mouse) out of a circ

Posted: Fri Oct 16, 2015 8:20 pm
by sinisrus