• Making a 2D Gamemode, need help with aiming system.
    20 replies, posted
Hey guys, I am making a 2D Gamemode, all the view stuff is done, most of all stuff is done, except the actual most important aspect in the gamemode, the aiming and shooting. I want my aim-system to be like [media]http://www.youtube.com/watch?v=A8sWNI-tImc[/media] , ofcourse it doesn't have to be a fancy crosshair like that. I just want so that my player can rotate and shoot by using the mouse. This is what I got now: [url]http://www.wegame.com/watch/aiming-gone-wrong/[/url] I can't turn around, only shoot up or down, in the position right. It would be very nice if you guys could help me with this, because i'm having a hard time figuring it out. I got this code now:[lua]local ply = LocalPlayer() local test = gui.ScreenToVector(gui.MousePos()) local Vec1 = test local Vec2 = ply:GetShootPos() local Ang = (Vec1 - Vec2):Angle() ply:SetEyeAngles( Ang )[/lua] But that didn't work, I tried setting gui.EnableScreenClicker, but it won't look/shoot at the mouse position then.
Can you post your camera code so I can see that too? I think I know how to do this. [editline]8th March 2011[/editline] Never mind about the camera, play around with this: [lua] local function DrawCrosshair() local tr = {} tr.start = LocalPlayer():GetShootPos() tr.endpos = tr.start + LocalPlayer():GetAimVector()*1000 tr.mask = MASK_ALL tr = util.TraceLine(tr) local pos = tr.HitPos:ToScreen() surface.DrawCircle(pos.x,pos.y,15,Color(0,200,0,255)) end hook.Add("HUDPaint","DrawCrosshair",DrawCrosshair) [/lua] You multiply by how many units ahead you want it to be.
That didn't quite work. I don't see any circles, or crosshairs on my screen at all, for your information, I placed it in cl_init, if that's alright.
That's very weird, it worked fine for me. It should point 1000 units ahead of where you're aiming.
Did you maybe enable gui.EnableScreenClicker, or? I can't see any crosshair or circle or whatever. Wait, I do see the circle when I set line 4 to tr.endpos = tr.start + LocalPlayer():GetAimVector()*0, but then the circle just stays in the middle.
Post me your camera code. All I did was open sandbox and run that. [editline]8th March 2011[/editline] [QUOTE=Staneh;28497248]Did you maybe enable gui.EnableScreenClicker, or? I can't see any crosshair or circle or whatever. Wait, I do see the circle when I set line 4 to tr.endpos = tr.start + LocalPlayer():GetAimVector()*0, but then the circle just stays in the middle.[/QUOTE] Then adjust the length.
[lua]scrollview = -200 function MyCalcView(ply, pos, angles, fov) local view = {} view.origin = pos + Vector(scrollview,0,0) view.angles = Angle(0,0,0) view.fov = fov return view end hook.Add("CalcView", "MyCalcView", MyCalcView) function GM:Think() scrollview = math.Clamp( scrollview, -500, -60 ) if ( input.IsKeyDown( KEY_T ) ) then scrollview = scrollview + 20 elseif ( input.IsKeyDown( KEY_G ) ) then scrollview = scrollview - 20 end end hook.Add("ShouldDrawLocalPlayer", "MyHax ShouldDrawLocalPlayer", function(ply) return true end) hook.Add("CreateMove", "LockMyView", function(ucmd) ucmd:SetViewAngles(Angle(ucmd:GetViewAngles().p, -90, 0)) end)[/lua] This is my camera code, but, I kind of got it working, it's just that, the player can't rotate when he looks to the left. I need to rotate too. The think hook is for scrolling the view closer and further away. CreateMove is there to prevent the player from looking left or right.
You're preventing the player from looking left, but he can't rotate to the left? You just answered your own question.
Well, at the first sentence I ment literally to the left, and at the second sentence I ment of the forward position of the player.
Try commenting out that view angles line.
[img]http://img651.imageshack.us/i/naamloospse.jpg/[/img] This blocks the player from looking in the arrow's directions.
Bump, I really need someone to help me with this.
[QUOTE=Staneh;28507586]Bump, I really need someone to help me with this.[/QUOTE] What is it exactly that is not working? [editline]9th March 2011[/editline] Any errors?
I want the aiming system to be like in the Deathrun video, that theres a dot where your mouse is. But the examples given didn't match my question.
This is what I made for my 2D "RecycleIt!" gamemode, you are free to use it: [lua] function GM:CreateMove( cmd ) local Pl = LocalPlayer() local MousePosition = gui.ScreenToVector(gui.MousePos()) local MousePositionx, MousePositiony = gui.MousePos() if ( Pl:Alive() and Pl:Team() != TEAM_SPECTATOR ) then cmd:SetForwardMove( cmd:GetSideMove() ) local ang local shootingpos = ( Pl:GetShootPos() ):ToScreen() local sumx = (MousePositionx - 10) - shootingpos.x local sumy = (MousePositiony - 10) - shootingpos.y ang = math.Rad2Deg( math.atan2( sumy, sumx ) ) if MousePosition.y <= 0 then cmd:SetViewAngles( Angle( math.NormalizeAngle(ang), -90, 0 ) ) else cmd:SetViewAngles( Angle( math.NormalizeAngle(180 - ang), 90, 0 ) ) cmd:SetForwardMove( -cmd:GetSideMove() ) end cmd:SetSideMove( 0 ) end end [/lua]
Well, it didn't help the aiming, it flipped my player viewangle, but I can't aim at all right now.
[QUOTE=Staneh;28511747]Well, it didn't help the aiming, it flipped my player viewangle, but I can't aim at all right now.[/QUOTE] Of course because that was made for my gamemode. Make the pointer appear, I use an invisible derma panel which uses gui.EnableScreenClicker( true ) to show the pointer. This basically gets the position of the pointer and translates it so that it becomes player's aim pointer as well changing its angles when left/right.
Oh, I understand now, let me try it. [editline]9th March 2011[/editline] [QUOTE=Wolfo;28512024]Of course because that was made for my gamemode. Make the pointer appear, I use an invisible derma panel which uses gui.EnableScreenClicker( true ) to show the pointer. This basically gets the position of the pointer and translates it so that it becomes player's aim pointer as well changing its angles when left/right.[/QUOTE] Oh man, you're my hero. It works, although, I can't shoot right now, any way to make the player so he can shoot?
[QUOTE=Staneh;28512072]Oh, I understand now, let me try it. [editline]9th March 2011[/editline] Oh man, you're my hero. It works, although, I can't shoot right now, any way to make the player so he can shoot?[/QUOTE] Might help? [lua] function GM:GUIMousePressed(mc) if mc == MOUSE_LEFT then RunConsoleCommand("+attack") elseif mc == MOUSE_RIGHT then RunConsoleCommand("+attack2") end end function GM:GUIMouseReleased(mc) if mc == MOUSE_LEFT then RunConsoleCommand("-attack") elseif mc == MOUSE_RIGHT then RunConsoleCommand("-attack2") end end [/lua] This will work only if the pointer is NOT on a derma.
I remembered your thread when I found this: [url]http://deathrun2d.googlecode.com/svn/trunk/[/url] <3 Ha3
8:53 PM - Hatefuleagle: all he needs to use is RotateAroundAxis when the mouses x pos is less than the players x position relative to the screen 8:54 PM - Hatefuleagle: [lua]function MouseMove(cmd) if ( !LocalPlayer():Alive() ) then return end local ply = ( LocalPlayer():GetPos() + Vector(0, 0, 64) ):ToScreen() local vec = Vector( ply.x, ply.y, 0 ) local pos = Vector( gui.MouseX(), gui.MouseY(), 0 ) local angle = ( pos-vec ):Angle() local dirang = 0 if ( pos.x > ply.x ) then side = 180 angle.y = math.AngleDifference( angle.y, 360 ) cmd:SetForwardMove( cmd:GetSideMove() ) else angle:RotateAroundAxis( Vector(0, 0, 1), 180 ) angle.y = -angle.y side = 0 angle.y = math.AngleDifference( angle.y, 360 ) cmd:SetForwardMove( -cmd:GetSideMove() ) end cmd:SetViewAngles( Angle(angle.y, side, 0) ) cmd:SetSideMove( 0 ) end hook.Add("CreateMove", "MouseMove", MouseMove)[/lua] 8:54 PM - Hatefuleagle: litteral copy paste from mine 8:55 PM - Jo The Shmo: are you going to post in the thread 8:55 PM - Hatefuleagle: nah 8:55 PM - Hatefuleagle: I don't ever post on FP He made a gamemode similar to the one in the OP a few months ago and it worked great.
Sorry, you need to Log In to post a reply to this thread.