Unreal Engine 4 C + + Ray collisions

Source: Internet
Author: User

In the game development often uses the ray collision, for instance the laser shot, needs to know clearly its centralized position, then releases the attack effect at this point.

Unrea Engine 4 To do Ray collision is also very simple, the main function of the implementation is the world Linetracesingle this method, the following gives the test code. The code I tested in Thirdpersontemplate. Detects the actor in front of the character with or without a bump, and displays a debug ball on the collision point. The code is as follows:

void Ananprojectcharacter::raycast () {Fhitresult hitresult (forceinit); Fvector Pos, dir; Fcollisionqueryparams CCQ (FName (TEXT ("Combattrace")), true, NULL); Ccq.btracecomplex = True;ccq.btraceasyncscene = False;ccq.breturnphysicalmaterial = False;ccq. Addignoredactor (this);p OS = getactorlocation (); const Frotator Rotation = Capsulecomponent->getcomponentrotation () ; Const Frotator yawrotation (0, Rotation.yaw, 0);//Get forward Vectordir = Frotationmatrix (yawrotation). Getunitaxis (EAXIS::X); Fvector posbegin = pos; Fvector posend = pos + dir * 500; Getworld ()->linetracesingle (HITRESULT,POSBEGIN,POSEND,ECC_WORLDSTATIC,CCQ);D Rawdebugline (This->GetWorld ( ), Posbegin, Posend, Fcolor (1.0f, 0.F, 0.F, 1.f), False, 20.F), if (Hitresult.getactor ()) {Drawdebugsphere (Getworld (), Hitresult.location, ten, fcolor::red, false, 20.F);}}


Note that you need to exclude the character from the collision detection itself. The final effect is as follows:



Unreal Engine 4 C + + Ray collision

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.