Комментарии:
Hello! Thank you very much for the tutorial! I'm having issues when I set the camera to perspective mode. It only works correctly if it's in orthographic mode. Has anyone else experienced this? How can I solve it?
ОтветитьFollowed the video and on finish the line renderer seems like it's attached to the ball object, so when i drag it spawns the line next to the ball rather than where I click. Did I miscode it or miss box tick in a menu or something?
Either way awesome video :) thanks for putting it out
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerScript : MonoBehaviour
{
public float power = 10f;
public Rigidbody2D rb;
public Vector2 minPower;
public Vector2 maxPower;
Camera cam;
Vector2 force;
Vector3 startPoint;
Vector3 endPoint;
private void Start()
{
cam = Camera.main;
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
startPoint = cam.ScreenToWorldPoint(Input.mousePosition);
startPoint.z = 15;
Debug.Log(startPoint);
}
if (Input.GetMouseButtonUp(0))
{
endPoint = cam.ScreenToWorldPoint(Input.mousePosition);
endPoint.z = 15;
force = new Vector2(Mathf.Clamp(startPoint.x - endPoint.x, minPower.x, maxPower.x), Mathf.Clamp(startPoint.y - endPoint.y, minPower.y, maxPower.y));
rb.AddForce(force * power, ForceMode2D.Impulse);
}
}
}
Неверно рассчитывается вектор импульса (46 строка)
ОтветитьOn dragging it actually control the ball throwing force like( if mouse dragging length is short the force applied on the ball is low competitive the longer drag).
ОтветитьMy left ear really enjoyed that one
ОтветитьIf you want to make it so you can only drag when the object is still, Then the DragNShoot script will be this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public float power = 10f;
public Rigidbody2D rb;
public Vector2 minPower;
public Vector2 maxPower;
TragectoryLine tl;
Camera cam;
Vector2 force;
Vector3 startPoint;
Vector3 endPoint;
bool isStill = true;
private void Start()
{
cam = Camera.main;
tl = GetComponent<TragectoryLine>();
}
private void Update()
{
if (rb.velocity == new Vector2(0, 0))
{
isStill = true;
}
else
{
isStill = false;
}
if (Input.GetMouseButtonDown(0) && isStill == true)
{
startPoint = cam.ScreenToWorldPoint(Input.mousePosition);
startPoint.z = 15;
}
if (Input.GetMouseButton(0) && isStill == true)
{
Vector3 currentPoint = cam.ScreenToWorldPoint(Input.mousePosition);
currentPoint.z = 15;
tl.RenderLine(startPoint, currentPoint);
}
if (Input.GetMouseButtonUp(0) && isStill == true)
{
endPoint = cam.ScreenToWorldPoint(Input.mousePosition);
endPoint.z = 15;
force = new Vector2(Mathf.Clamp(startPoint.x - endPoint.x, minPower.x, maxPower.x), Mathf.Clamp(startPoint.y - endPoint.y, minPower.y, maxPower.y));
rb.AddForce(force * power, ForceMode2D.Impulse);
tl.EndLine();
}
}
}
Here I created a bolean called "isStill".
And in the void Update() I made isStill = true if the velocity of the rigid body is = new Vector2(0, 0)
And if its not (else), then isStill = false.
And then for each if statement we made I added (&& isStill ==true) to make sure the object is still to be able to perform this action
What if I want to check is gameObject still? (Cant shoot mid air)...
ОтветитьI subscribed
Ответитьi want to add cooldown for this shooting thing. please answer and tell us how we can add cooldown for this game please
Cheers
-your lovely followers :)
Dummy question here: I have a ball with 9 child bones( to create the soft body effect). Initially, the script applied only to the rigid body "Ball" had no effect, so I've added the same script also to each bone and it works perfectly. With that said, is there another way of doing it? Not sure if that's the most lean way. Thanks
ОтветитьThank You For The Tutorial! I Am Working On A Stickman Game And With This I Can Make It Have Unique Movement
Ответитьidk if you are gonna respond to this because it's been 2 years sience you made this video
but the tutorial is great i just have an issue with it: the players can spam it and they can fly so how do i make like a cooldown system or that if the player stops moving then they can move again or something?
The script worked but the effect would only show a dot
ОтветитьGreat Tutorial! But unfortunetly it didn't work for me but you know it's okay, It was good explaining and atleast i learned alot with input, Thank you!
ОтветитьI can't thank you enough, it works, figured the first time didn't work because I got some lines wrong
ОтветитьI just don't understand what's the first parameter in the Mathf.Clamp( ) function and I don't get the use of it. Otherwise, everything else is clear.
Thank You!
When I try to add another line renderer for my player to make it so it has a trail while its moving and its not working. Does anyone know how to fix this?
ОтветитьAlso, anytime I drag and shoot and collide with 2 or 3 box collider platforms, the drag and shoot doesnt work. Any fix?
ОтветитьYour video helped me to start developing a game that will be amazing. When I finish and upload it on steam you will get it for free.
ОтветитьIve 1 to 1 followed the tutorial. The ball doesnt shoot. Help
ОтветитьFor some reason didn't work for me . Debug force showing (0,0,0)
here is my code: , I think it's the same as on video
public class dragNShoot : MonoBehaviour
{
public float power;
public Rigidbody2D rb;
public Vector2 minPower;
public Vector2 maxPower;
Camera cam;
Vector2 force;
Vector3 startPoint;
Vector3 endPoint;
private void Start()
{
cam = Camera.main;
}
private void Update()
{
if(Input.GetMouseButtonDown(0))
{
startPoint = cam.ScreenToWorldPoint(Input.mousePosition);
startPoint.z = 15;
}
if (Input.GetMouseButtonUp(0))
{
endPoint = cam.ScreenToWorldPoint(Input.mousePosition);
endPoint.z = 15;
force = new Vector2(Mathf.Clamp(startPoint.x - endPoint.x, minPower.x, maxPower.x), Mathf.Clamp(startPoint.y - endPoint.y, minPower.y, maxPower.y));
rb.AddForce(force * power, ForceMode2D.Impulse);
Debug.Log(force);
}
}
}
**
so i was wondering, how do you make it so you can only use it a certain amount of times when you are in the air and when you touch the ground it resets?
ОтветитьHow do I attach the line to the ball so no matter where a touch,it looks like i started from the ball
ОтветитьAwesome tutorial.
First thing i will try tomorrow morning after my round of golf.
Thanks a lot.
ОтветитьThis was definitely useful. Thanks a lot for creating this tutorial.
Ответитьthis didn't work for me and i have no idea what to do he tell me the cam doesn't exist
Ответитьnice tutorial, but how about on a 2d project with perspective camera?
ОтветитьForce = Vector2(Mathf.Clamp(startPoint.x - endPoint.x, minPower.x, maxPower.x), Mathf.Clamp(startPoint.y - endPoint.y, minPower.y, maxPower.y));, this is and error it says u cant use VEctor 2 like a method.
ОтветитьAwesome tutorial!
ОтветитьHow to make it limited like 3 shots then its gameover
ОтветитьA great video! Just what I'm looking for, thanks!!
ОтветитьIt's a 3D project, but we can change the z value to y value. Thank you very much for making a very useful tutorial. I wish you happiness.
ОтветитьGreat Vid! But is there a way you can drag and shoot once until you hit the ground so you won't keep shooting up in the air?
ОтветитьOMG thank you so much, i've tried to do this for 3 days and finally it's working, thank you !
Ответитьthank you so much Muddy Wolf games. This was really helpful for me!
ОтветитьGreat video - thanks!
ОтветитьThanks
ОтветитьHey excellent video but I have a question
How do you get the autocomplete and definition thing for unity because when I type it doesn't show all the options you have
heemmmmm why the ball do not move in my variant
ОтветитьWhy my player jump in only y axis
ОтветитьCan someone help for some reason the ball only goes in on direction
ОтветитьHey man, I've really liked your tutorial and it helped me a lot; but can you help me with something? After I added animation to the script the ball only jumps straight in the air, it doesn't jump on the right or left part, do you know any solution for this? Thanks in advance!
Ответить