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 / Screen position at this distance from sprite that is angled?

Author
Message
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 2nd Apr 2011 01:34 Edited at: 2nd Apr 2011 02:30
I feel really stupid as i cant get a code to work where i want to find the x y position, at an specific distance in front of the player sprite even when he turns.
Simply so do i want to always find the point in front of the player

Its in 2d that aint my strongest point !

Edited...........
I have solved it
Old...
sprite linecast,PL_X,PL_y,4
rotate sprite linecast,wrapvalue(PL_A#-ang_step#)
move sprite linecast,400
New...
spritex# = PL_X + (cos(wrapvalue((PL_A#-90))-ang_step#)*View_distance)
spritey# = PL_y + (sin(wrapvalue(PL_A#-90)-ang_step#)*View_distance)

And i gained 260 fps as i run this in every loop
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Apr 2011 09:54
Rather than run that in every loop, only calculate the new sprite position when the player's sprite has rotated to a new position. No need to recalculate it if it hasn't changed.

The Internet: Where men are men, women are men, and children are federal agents
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 6th Apr 2011 17:51
There are also commands that do this for you,

Return Float=NEWXVALUE(Current X Value, Angle Value, Step Value)

Return Float=NEWYVALUE(Current Y Value, Angle Value, Step Value)

Return Float=NEWZVALUE(Current Z Value, Angle Value, Step Value)

These commands are used to move from one point in space to another point in space based on a specified angle. Rather than using COS/SIN maths, these commands simplify the task of moving coordinates within 3D space. The step value specifies how far in the specified direction you would like to calculate. The parameters should be specified using real numbers.

Although they work in 3D space, if you use just the x and z versions, they work fine in 2D space as well.

Login to post a reply

Server time is: 2024-11-24 05:00:38
Your offset time is: 2024-11-24 05:00:38