Vice City Multiplayer
VC:MP 0.4 (Beta) => Script Discussion => Topic started by: Honey. on October 02, 2014, 01:44:23 pm
-
Hello,
I needed help in rotating sprites.I am trying to use SetRotationForPlayer( player, rotation ) but i get no errors and nothing happens.
I try to rotate it like this :
s <-CreateSprite( "spritename.png", 500, 600, 0, 0, 0,255 );
s.ShowForPlayer( FindPlayer( player ) );
s.SetRotationForPlayer(player, 150);
-
Hmm i also have this error but it shows error in console
Saying that cannot find member variable
-
s.RotateForPlayer(player, 150);
-
That function does rotate the sprite but doesn't rotate the sprite I want but instead makes a new sprite and rotates that!
Multiple Sprites was a bug of my script which i fixed later but now there is a new problem.The needle's position keeps changing on the screen while moving.If my car stays still it doesn't move but If my car is not still it dances on the screen.
-
Maybe because you rotate the sprite when position is changed ?! (or in a speedometer script?)
-
Maybe because you rotate the sprite when position is changed ?! (or in a speedometer script?)
If you mean the position of the player is changed then you're right.The player position is contantly changing while it is driving.
-
Post some more code. A sprite doesn't dance on your screen unless you tell it to.
-
Post some more code. A sprite doesn't dance on your screen unless you tell it to.
Here you go :
function onScriptLoad()
{
// Other Functions
NewTimer( "Speedometer", 1500, 0 );
s <-CreateSprite( "needle.png", 500, 500, 0, 0, 0,255 );
// other functions
}
function Speedometer()
{
for ( local i = 0; i < GetMaxPlayers(); i++ )
{
local p = FindPlayer( i );
if ( p )
{
if ( p.IsSpawned )
{
local vehicle = p.Vehicle;
if ( vehicle )
{
local Speed = sqrt(vehicle.Speed.x*vehicle.Speed.x + vehicle.Speed.y * vehicle.Speed.y + vehicle.Speed.z * vehicle.Speed.z) * 50 * 3.6;
local output = round(Speed, 0);
s.RotateForPlayer( p, output );
}
}
}
}
}
function onPlayerEnterVehicle( player, veh, isPassenger )
{
s.ShowForPlayer( player );
}
function onPlayerExitVehicle( player, veh )
{
s.HideFromPlayer( player );
}
This is all of the code I have used.
-
Here is a video ( sorry for the bad quality, I compressed the video too much :-\ ) :
(http://i1368.photobucket.com/albums/ag163/honeyr697/th_Needle_zpsca08ea00.mp4) (http://i1368.photobucket.com/albums/ag163/honeyr697/Needle_zpsca08ea00.mp4)
-
Bump!!
-
The sprites are fine, the problem is your math. Objects are rotated about an axis of 360 degrees. If a player is going 1km/h, your sprite rotates 180 degrees. If a player is going 2km/h, your sprite rotates 360 degrees. It will only rotate to 0 or 180 degrees or some derivative of it, and especially because you round to the nearest whole number.
-
The sprites are fine, the problem is your math. Objects are rotated about an axis of 360 degrees. If a player is going 1km/h, your sprite rotates 180 degrees. If a player is going 2km/h, your sprite rotates 360 degrees. It will only rotate to 0 or 180 degrees or some derivative of it, and especially because you round to the nearest whole number.
Can you explain more? I didn't quite understand what you meant.
Secondly rotation problems is a different case why does the sprite move in random positions?
-
The sprites are fine, the problem is your math. Objects are rotated about an axis of 360 degrees. If a player is going 1km/h, your sprite rotates 180 degrees. If a player is going 2km/h, your sprite rotates 360 degrees. It will only rotate to 0 or 180 degrees or some derivative of it, and especially because you round to the nearest whole number.
Can you explain more? I didn't quite understand what you meant.
I don't know how to explain this any further without having to teach trigonometry.
Secondly rotation problems is a different case why does the sprite move in random positions?
I'm going to say because you didn't remove whitespace/transparency around the speedometer sprite.
-
Is whitespace created when we enter in the vehicle by pressing the enter button? I read that :
Vertical white space is a bit more varied as to how it is encoded,but the most obvious in typing is the ↵ Enter result which creates a 'newline' code sequence in applications programs
Where is the whitespace created and how do I remove it?
Sorry for being a noob here ;)
-
Whitespace is created when you have a PNG with transparency around the image.