Forum

> > CS2D > Scripts > Bloodsplash on wall based on direction from hit
Forums overviewCS2D overview Scripts overviewLog in to reply

English Bloodsplash on wall based on direction from hit

10 replies
To the start Previous 1 Next To the start

old Bloodsplash on wall based on direction from hit

Alistaire
User Off Offline

Quote
90 and 270 worked, but it seems that I've somehow used y + 1 instead y - 1 for the upper right corner etc.

Sorry

Spoiler >
edited 3×, last 23.04.12 03:45:02 pm

old Re: Bloodsplash on wall based on direction from hit

EngiN33R
Moderator Off Offline

Quote
Unless I'm not getting something, I don't see a declaration of the 'm' variable which you compare with numbers.

This could also be done dynamically with one image being rotated depending on the angle which a player was shot from.

old Re: Bloodsplash on wall based on direction from hit

Alistaire
User Off Offline

Quote
The m value is player(source, 'rot').

----

The script has no errors, but there aren't any images showing up either.

I know it can be done with the same image being rotated, but I want to make a stable base for the script.

----

When I throw a grenade and face in the opposite direction of the wall close to the enemy, the images work. If I shoot at him when he's close to a wall, nothing happens.

old Re: Bloodsplash on wall based on direction from hit

DC
Admin Off Offline

Quote
Just a stupid question: You are aware of the fact that this already happens in CS2D by default without any scripts?

Also I think that the returned angle (m) can be negative as well. Maybe you have to add 360 until it becomes positive before running your set of conditions.
edited 1×, last 23.04.12 02:26:52 pm

old Re: Bloodsplash on wall based on direction from hit

DC
Admin Off Offline

Quote
No, it's calculated with atan2 using the player and the mouse position / the difference between those. I think it might return negative angles. Negative angles are pretty common in programming.

old Re: Bloodsplash on wall based on direction from hit

Alistaire
User Off Offline

Quote
user DC has written
No, it's calculated with atan2 using the player and the mouse position / the difference between those. I think it might return negative angles. Negative angles are pretty common in programming.


So I should use;

1
2
3
if m < 0 then 
	m = m * - 1
end

Or;

1
2
3
4
5
6
7
8
9
10
11
while m < 0 or m > 360 do
	if m < 0 then
		if m * - 1 < 360 then
			m = m * - 1
		else
			m = m + 360
		end
	elseif m > 360 then
		m = m - 360
	end
loop

?

old Re: Bloodsplash on wall based on direction from hit

DC
Admin Off Offline

Quote
Don't do that *(-1) stuff it will lead to wrong results!
-90° equals 270° and NOT 90° for example.

Most primitive approach:
1
2
3
while m<0 do
	m=m+360
end
(I don't expect that values>360 will occur)

You can probably also do it with modulo and without a loop.

old Re: Bloodsplash on wall based on direction from hit

Alistaire
User Off Offline

Quote
user DC has written
Most primitive approach:
1
2
3
while m<0 do
	m=m+360
end


So to be sure I should print the player rotation every time it changes to see if it can be over 360 or under 0, and base the script on it.

I find it weird how, when I throw a HE grenade and look the opposite direction, it returns 2 rotations tho.

----

It seems that player(id, 'rot') is -180 to 180
(not 0 to 360)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview